| 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:
to open fibonacci.asm.
. The display should switch
from the Edit view to the Execute view.
to change
the run speed to about 10 instructions per second. This allows us
to watch the action instead
of the assembly program finishing directly.
icon runs
the program to completion. Using this icon, you should observe the
yellow highlight showing the programs progress and
the values of the Fibonacci sequence appearing in the $t2 register
in the Registers display. Turn off Hexadecimal Values to
see the values in decimal.
icon resets the program and simulator to initial values. Memory contents
are those specified within the program, and register contents are
generally zero.
icon performs single-step:
one instruction is performed and then the simulation stops.
icon; this undoes each single operation.
The Fibonacci numbers below 1 million are 1 1 2 3 5 8 ...
to continue
from the breakpoint. The program now uses your entered value instead
of the computed Fibonacci number.
icon for information on MIPS instructions, pseudoinstructions, directives,
and syscalls.
,
and single-step your program.