CS/CoE 0447 Computer Organization Fall 2023
μMIPS Assembler Reference Manual November 14, 2023 (ISA version 0.9.9)
This document describes the rudimentary assembler for μMIPS. The assembler is available from the course website.
The assembler uses Perl. You’ll need access to Perl to use the assembler. You can get Perl from:
http://www.perl.com/download.csp
1) Assembly Language Syntax
The μMIPS assembler supports the instructions and assembly language syntax:
nand $rs,$rt or $rs,$rt add $rs,$rt addi $rs,imm addi $rs,dlabel sub $rs,$rt div $rs,$rt mul $rs,$rt sllv $rs,$rt srlv $rs,$rt lw $rs,$rt sw $rs,$rt li $rs,imm bp $rs,label bn $rs,label bz $rs,label bx $rs,label jal $rs,label jr $rs
j label not $rs,$rt nor $rs,$rt and $rs,$rt clr $rs
(this is equivalent to la below)
(load immediate into $rs)
(pseudo instruction)
(pseudo instruction)
(pseudo instruction)
(pseudo instruction: set $rs to 0)
(pseudo instruction: load address of data label dlabel into $rs)
(pseudo instruction: copy value from register $rt into register $rs)
where, $rs and $rt are one of names $r0, $r1, $r2, $r3, $r4, $r5, $r6, $r7;
la $rs,dlabel put $rs
mov $rs, $rt halt
a symbolic label name declared in the text segment; a symbolic label name declared in the data segment; and,
imm is a signed constant decimal or hexadecimal value.
Computer Science Tutoring
The assembler supports hexadecimal notation for values (immediates). To indicate hexadecimal, use “0x” before the value (e.g., 0xF00F is valid). A hex value may only be used in a location where an immediate value is expected, including instructions with an immediate (the last operand) or labels in the data segment.
Labels are allowed, but they must start with a letter and end with a colon. Labels are case insensitive. For example, the label LABEL0 is the same as Label0.
The μMIPS assembler supports a text and data segment. For the data segment, use the directive “.data” by itself on a line to begin the data segment. In this segment, you can declare initialized 16-bit word values. Each value may have a label. The syntax is:
label: value
where label is a symbolic name and value is the value to associate with the label. Unlike MIPS, you do not declare a type. All items in the data segment are 16-bit words. Every value must be declared on a line by itself with its own label. Hence, you cannot have a sequence of values separated by commas.
The data in the data segment must be processed and loaded separately from the text segment. The assembler option “-d” will output the data values in a form that can be loaded into a Logisim RAM component.
The text segment is the default. If you use a data segment, be sure to switch to the text segment with the “.text” directive.
Comments and blank lines are allowed. A comment is given with a semicolon (“;”).
There is almost no error checking by the assembler, so tread carefully.
2) Assembling a Program
To run the assembler, use the command:
perl umipsasm.pl progname.asm
This will cause progname.asm to be assembled. The assembler will output hex encoding for the instructions to the display. The output is in a format that can be loaded directly from within Logisim into a ROM component.
To save the output from the assembler to a file, use the command:
perl umipsasm.pl progname.asm > progname.m
Then, load progname.txt into ROM from Logisim. To load a program into ROM, open your processor design in Logisim, poke the ROM, and click on the ROM’s Load contents attribute. Select the filename with the encoded program.
To output the data segment, use the “-d” option:
perl umipsasm.pl -d progname.asm > progname.dat
Then, load progname.dat into RAM. Click on the RAM and press Control (control-click). This will bring up a menu option “Load Image”, which will set the RAM to the contents in the file. You need to reload the RAM every time you reset the simulation.
The assembler supports some command line options:
• An option (“-p”) disables all pseudo-instructions.
• A second option (“-v”) causes the assembler to print verbose information about the assembled program. This option is useful to verify that the assembler generated the correct output.
• A third option (“-l “) will cause the assembler to dump the addresses it used for the labels in the input assembly language program.
• A final option (“-d”) causes the assembler to output data segment information.
Code Help
Appendix: Example Programs
Here is an example program:
# increment from 0 to 15
# lowest hex digit will cycle from ‘0’ to ‘F’
# output current value # increment value by 1 # check for loop end # end of loop?
The assembled instruction file is:
# μMIPS ISA version v0.9.9 14/11/23
addi $r1, 1
mov $r2, $r1
addi $r2, -16
bn $r2, loop0
# 4) load the saved file
load this file into Logisim:
save the output from the assembler to a file
use the poke tool in Logisim and control-click the ROM/RAM component select Load Image menu option
浙大学霸代写 加微信 cstutorcs
This is a second program with a data section:
b: 0 .text
# Remember: “la” is a pseudo instruction!! la $r1,a
lw $r2,$r1
add $r3,$r2
addi $r2,-1
bp $r2,loop
sw $r3,$r1
lw $r4,$r1
put $r4 # answer should be 0x37 halt
The assembled instruction file is:
# μMIPS ISA version v0.9.9 14/11/23
# 4) load the saved file
load this file into Logisim:
save the output from the assembler to a file
use the poke tool in Logisim and control-click the ROM/RAM component select Load Image menu option
The data section file (loaded into the RAM) is:
# μMIPS ISA version v0.9.9 14/11/23
# 4) load the saved file
load this file into Logisim:
save the output from the assembler to a file
use the poke tool in Logisim and control-click the ROM/RAM component select Load Image menu option