Mips
Mips
Reference Guide
Free at PushingButtons.net
2
Table of Contents
I. Data Registers 3
V. SPIM Programming 11
Data Registers
# Register(s) Usage
0 $zero Hard-wired to 0
1 $at Reserved for assembler
2,3 $v0, $v1 Used to store returned values from function calls
4-7 $a0 - $a3 Used to store values passed as arguments to functions
8-15 $t0 - $t7 Temporary registers
16-23 $s0 - $s7 Saved temporary registers
24,25 $t8, $t9 Temporary registers
26, 27 $k0, $k1 Reserved for operating system kernel
28 $gp Global pointer
29 $sp Stack pointer
30 $fp Frame pointer
31 $ra Return address for function calls
4
R Format
Op-Code Rs Rt Rd Rh Function
Code
000000 sssss ttttt ddddd hhhhh ffffff
I Format
Op-Code Rs Rt Immediate
ffffff sssss ttttt iiiiiiiiiiiiiiii
J Format
Op-Code Target
ffffff iiiiiiiiiiiiiiiiiiiiiiiiii
The R (register) format consists of five different fields. The 6-bit op-
code will always be 000000. Rs, Rt and Rd are 5-bit fields that specify the
locations of registers being used. Rs and Rt are sources for the operation.
Rd is the destination to store the result. If Rh (shift amount) is not used, it
becomes 00000. The last 5 bits are the function code. This tells the
computer which type of instruction should be executed.
The J (jump) format consists of only two fields. The 6-bit op-code will
always be 00001f. The last 26 bits specify the location being jumped to.
These type of instructions are similar to high-level language “go to”
commands.
5
J j target jump
Meaning Jump to target location
additional info Op-Code 000010
JR jr $s jump register
Meaning Jump to target location
contained in register $s
additional info Function Code 001000
OR or $d, $s, $t or
Meaning $d = $s or $t
additional info Function Code 100101
SPIM Programming
Within the data segment you can initialize your variables. All variables are
initialized in the form:
The name is user defined. It can be any name the programmer wishes to
call the variable by. The variable types are the following:
.ascii ASCII string
.asciiz ASCII string followed by a null
terminator
.byte Byte
.doubl Double
e
.float Float
.word Word
Program Examples
#This program prints to screen the string “Hello World!”
#If hello is called within the main program it will lead to the string.
#.asciiz means that the string is in ASCII format followed by
#a NULL terminator
hello: .asciiz "Hello World!"
.globl main
.globl main
#This program asks the user for two integers and then displays the sum
.globl main
#This program asks the user for two numbers and displays their product
.globl main
#This program asks the user for an integer and then determines if it
#is even or odd
.globl main