Register | Mnemonic Name | Purpose |
0 | zero | the value 0 |
1 | $at | (assembler temporary) Reserved by the assembler |
2-3 | $v0 - $v1 | (values) from expression evaluation and function results |
4-7 | $a0 - $a3 | (arguments) First four parameters for subroutine. Not preserved across procedure calls |
8-15 | $t0 - $t7 | (temporaries) Caller saved if needed. Subroutines can use w/out saving. Not preserved across procedure calls |
16-23 | $s0 - $s7 | (saved values) Callee saved. A subroutine using one of these must save original and restore it before exiting. Preserved across procedure calls |
24-25 | $t8 - $t9 | (temporaries) Caller saved if needed. Subroutines can use w/out saving. Not preserved across procedure calls |
26-27 | $k0 - $k1 | Reserved for use by the operating system kernel |
28 | $gp | global pointer. Points to the middle of the 64K block of memory in the static data segment. |
29 | $sp | stack pointer. Points to last location on the stack. |
30 | $s8 or $fp | saved value / frame pointer. Preserved across procedure calls |
31 | $ra | return address |
.dataThere can be several data sections, but good style recommends a single data section at the top. This section is followed by
.textYour code section must contain a starting point for your program's execution, marked by the label
main:and your main code must end with a call to the exit system call, which tells the CPU to stop the program.
# Comments describing the purpose of this program, how to use it etc. # # .data # Data declarations follow this line # ... .text # Instructions follow this line main: # First instruction to execute # ... # ... li $v0, 10 # system call code for exit = 10 syscall # call operating systemWe have not yet covered the names of the MIPS instructions, nor how to write them with their operands; we will do this in future labs. For now, you should definitely read and absorb as much of the MIPS Assembly Cheat Sheet that you can.
$ java -jar Mars.jar # or whatever the jar file is calledWhen MARS runs, you should see a splash screen for a bit, and then you will get a window like this one:
The Fibonacci numbers below 1 million are 1 1 2 3 5 8 ...