Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
cag-uconn committed Aug 29, 2023
1 parent 89c8759 commit b124ca3
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 636 deletions.
37 changes: 24 additions & 13 deletions assembler/README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,52 @@
Mips Assembler
RISC-V Assembler
==============

An assembler for a subset of the MIPS like instruction set architecture
An assembler for a subset of the RISC-V instruction set architecture

# How to use
The assembler will take a file written in assembly language as input on the command line and will produce an output file containing the MIPS machine code. The input file should be in ASCII text. Each line in the input assembly file contains either a mnemonic, a section header (such as .data) or a label (jump or branch target. The maximum length of a line is 4 bytes. Section headers such as .data and .text should be in a line by themselves with no other assembly mnemonic. Similarly, branch targets such as loop: will be on a line by themselves with no other assembly mnemonic. The input assembly file should only contain one data section and one text section. The first section in the file will be the .text section, followed by the .data section.
The assembler will take a file written in assembly language as an input on the command line, and will produce an output file containing the RISC-V machine code. The input file should be in ASCII text. Each line in the input assembly file contains either a mnemonic, a section header (such as .data) or a label (jump or branch target). The maximum length of a line is 4 bytes. Section headers such as .data and .text should be in a line by themselves with no other assembly mnemonic. Similarly, branch targets such as loop: will be on a line by themselves with no other assembly mnemonic. The input assembly file should only contain one data section and one text section. The first section in the file will be the .text section, followed by the .data section.

The assembler supports the following instruction set:

R-Type
- add
- sub
- and
- or
- sll
- slt
- sll
- srl
- jr
- and
- or
- xor

I-Type
- lw
- sw
- andi
- jalr
- addi
- slti
- andi
- ori
- lui
- xori
- slli
- srli
- lw

S-Type
- sw

B-Type
- beq
- bne
- blt
- bge

J-Type
- j
- jal

U-Type
- lui

# Run
to compile the assembler
$ ./make
$ make

to run the assembler on a nop.asm assembly file to write machine code in nop.out
$ ./assembler nop.asm nop.out
47 changes: 26 additions & 21 deletions assembler/assembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,33 @@ int search(char *instruction);

// Array that holds the supported instructions
char *instructions[] = {
"la", // 0
"lui", // 1
"lw", // 2
"sw", // 3
"add", // 4
"sub", // 5
"addi", // 6
"add", // 0
"sub", // 1
"slt", // 3
"sll", // 4
"srl", // 5
"and", // 6
"or", // 7
"and", // 8
"ori", // 9
"andi", // 10
"slt", // 11
"slti", // 12
"sll", // 13
"srl", // 14
"beq", // 15
"bne", //16
"j", //17
"jr", //18
"jal" //19
};
"xor", // 8
"jalr", // 9
"addi", // 19
"slti", // 11
"andi", // 12
"ori", // 12
"xori", // 13
"slli", // 14
"srli", // 15
"lw", // 16
"beq", // 17
"bne", // 18
"blt", // 19
"bge", // 20
"sw", // 21
"jal", // 22
"lui" // 23
};



// Size of array
size_t inst_len = sizeof(instructions)/sizeof(char *);
Expand All @@ -44,7 +50,6 @@ int search(char *instruction) {
int found = 0;

for (int i = 0; i < inst_len; i++) {

if (strcmp(instruction, instructions[i]) == 0) {
found = 1;
return i;
Expand Down
Loading

0 comments on commit b124ca3

Please sign in to comment.