Professional Documents
Culture Documents
MIPS Instruction Formats: R-Type Format
MIPS Instruction Formats: R-Type Format
R-type format
I-type format
opcode rs rt address
6 5 5 16
J 10000 is represented as
2 10000
6-bits 26 bits
5 16 17 offset
6 5 5 16-bit offset
lw $t0, 0($t1)
j Loop
Exit:
6 5 5 5 5 6
80000 0 19 19 9 0 32 R-type
80004 0 9 9 9 0 32 R-type
80008 0 9 22 9 0 32 R-type
80012 35 9 8 0 I-type
80016 5 8 21 2 I-type
80020 0 19 20 19 0 32 R-type
80028
MIPS Addressing Modes
• Register addressing
Operand is in register
• Base addressing
Operand is in memory.
• PC-relative addressing
Main
procedure
($sp) decreases.
High address
Stack pointer
Item 1
(r29)
Item 2
$sp
Low address
Use of the stack in procedure call
Example
int f;
f = (g + h) – (i + j);
return f;
Now we can use the registers $t1, $t0, $s0 in the body
of the procedure.
sp
t1
t0
s0
Low
High
t1
t1
t0 t0
s0 sp s0
Low
Now restore the old values of the registers by popping
the stack.
ra
fact: sub $sp, $sp, 8 $fp
a0
sw $ra, 4($sp)
…
… 4000 push ra
return to old ra
ra = 1004
a0 = 3 a0 3
ra = 4024
a0 = 2
v0 result
ra= 4024
a0 = 1
$sp
Now test if n < 1 (i.e. n = 0). In that case return 0 to $v0
jr $ra # return