Professional Documents
Culture Documents
Mips 101
Mips 101
Fall 2004
Overview
(arguments)
(Instruction)
Fall 2004
#Programstartshere.
li$t0,5 #Loadtheintegervalue5
#intoregistert0
li$t1,19 #Load19intoregistert1
add$t2,$t1,$t0#Addregisterst0andt1
#toproducet2
li$v0,1 #Setupaprintintegercall
#toprinttheresult
move$a0,$t2
syscall
li$v0,10 #Setupanexitcall
syscall
#Dotheexitthing
Some opcodes
Required operands
Fall 2004
R3000
R4x00
MIPS IV
Fall 2004
R8000
R10000
R5000
SYCS-401 Operating Systems
Fall 2004
MIPS Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
General-Purpose Registers
Fall 2004
Fall 2004
MIPS Instruction
Categories
Arithmetic instructions
Logical instructions
Branch and jump instructions
conditional (branch)
unconditional (jump)
Fall 2004
Arithmetic Instructions
add
subtract
multiply
divide
compare
shift / rotate
Fall 2004
Arithmetic Instructions:
Add
Registers
ADD destinationReg, sourceReg, targetReg
Destination Source + Target
Fall 2004
Arithmetic Instructions:
Add
Unsigned
ADDU destinationReg, sourceReg, targetReg
Destination Source + Target
Fall 2004
Arithmetic Instructions:
Add
Immediate
ADDI destinationReg, sourceReg, targetReg
Destination Source + Target
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Arithmetic Instructions:
DivideDIVRegisters
sourceReg, targetReg
$lo (quotient), $hi (remainder) Source / Target
Fall 2004
Arithmetic Instructions:
Multiply
Registers
MUL sourceReg, targetReg
$lo (low word), $hi (high word) Source x Target
Fall 2004
Arithmetic Instructions:
Set
if Less Than
SLT destinationReg, sourceReg, targetReg
Destination Source < Target) ? 1 : 0
Fall 2004
Arithmetic Instructions:
SLT
Immediate
SLTI destinationReg, sourceReg, immediate
Destination Source < immediate) ? 1 : 0
Fall 2004
Fall 2004
Logical Instructions
Logical AND
logical OR
XOR
NOT
Fall 2004
Arithmetic Instructions:
Logical
AND
AND destinationReg, sourceReg, targetReg
Destination Source AND Target
Fall 2004
Arithmetic Instructions:
Logical
OR
OR destinationReg, sourceReg, targetReg
Destination Source OR Target
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
JAL label
Place the address of the next instruction (PC + 4) in $ra. Jump to the instruction at
label
Fall 2004
Fall 2004
Branch Instructions:
Branch on Equal
Fall 2004
Branch Instructions:
Branch if Equal to Zero
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Fall 2004
Assembler directives:
Examples
Fall 2004
Template.s
Fall 2004
Example.s
Fall 2004
Assembler Syntax
Comments
Identifiers
identifier:
Fall 2004
Examples:
Assume The existence of a 32b integer
(labeled x) is assumed:
.data
x:
.word 0
Fall 2004
If Construct
Fall 2004
If Construct
Fall 2004
If Construct
Fall 2004
Post-Test Loop
Fall 2004
Post-Test Loop
Fall 2004
#Programstartshere.
li$t0,5
#Loadtheintegervalue5
#intoregistert0
li$t2,$a0
#sett2=0
bltz$t0,done
#ift0<=0thengotodone
start:
add$t2,$t2,$t0#Addregisterst0andt1
#toproducet2
subi$t0,t0,1 #t0=t01
jstart
done:
li$v0,1
#Setupaprintintegercall
#toprinttheresult
move$a0,$t2
syscall
Fall 2004
li$v0,10
#Setupanexitcall
syscall
#Dotheexitthing
Fall 2004
Producing an Executable
Fall 2004
Procedure Calls
Fall 2004
Link Instructions
b*al
Fall 2004
Returning from a
procedure
jr$ra
Fall 2004
Procedure Calls
Fall 2004
Passing function
arguments
Fall 2004
Returning values
Fall 2004
The Stack
Fall 2004
Fall 2004
Procedure Call
Conceptually
Fall 2004
Caller Template
(Calling the function)
Fall 2004
Why subtraction?
Store any registers of interest
Why?
Fall 2004
$ra, $s0-$s7
Return
Fall 2004
jr $ra
SYCS-401 Operating Systems
Fall 2004
Sources
Indigo image and specs
http://www.sgi.com
For the R2000 instruction set
Patterson, D.A., & Hennesy, J.L., (1994).
ComputerOrganization and Design: The
Hardware / Software Interface, Morgan
Kaufmann. (Appendix A)
Available online at:
http://www.cs.wisc.edu/~larus/SPIM/codappa.pdf
Fall
For
the R3000 instruction
set
2004
SYCS-401 Operating Systems