Professional Documents
Culture Documents
5MD00 / 5Z033
MIPS
Instruction-Set Architecture
Henk Corporaal
www.ics.ele.tue.nl/~heco/courses/aca
TUEindhoven
2011
Topics
Arithmetic
Integer
Floating Point
Control flow
Jump
Conditional Branch
Call & Return
MIPS arithmetic
A = B + C
MIPS arithmetic
C code:
A = B + C + D;
E = F - A;
CPU
Memory
register file
IO
Register allocation
Memory Organization
8 bits of data
8 bits of data
8 bits of data
8 bits of data
8 bits of data
8 bits of data
...
Memory Organization
Bytes are nice, but most data items use larger "words"
For MIPS, a word is 32 bits or 4 bytes.
0
32 bits of data
32 bits of data
32 bits of data
...
12
32 bits of data
address
31
23
15
16
20
24
A[8] = h + A[8];
MIPS code:
lw $t0, 32($s3)
add $t0, $s2, $t0
sw $t0, 32($s3)
$2 ,
$2 ,
$15,
$16,
$16,
$15,
$31
$5, 4
$4, $2
0($2)
4($2)
0($2)
4($2)
MIPS
loading words but addressing bytes
arithmetic on registers only
Instruction
Meaning
Instructions, like registers and words of data, are also 32 bits long
Instruction Format:
op
rs
rt
rd
000000
10001
10010
01000
5 bits
5 bits
6 bits
5 bits
shamt
00000
5 bits
funct
100000
6 bits
18
op
rs
rt
32
16 bit number
Control
Example:
if (i==j) h = i + j;
Control
Instruction Meaning
add $s1,$s2,$s3
sub $s1,$s2,$s3
lw $s1,100($s2)
sw $s1,100($s2)
bne $s4,$s5,L
beq $s4,$s5,L
j Label
Next
Formats:
R
op
rs
rt
rd
op
rs
rt
16 bit address
op
shamt
26 bit address
funct
Control Flow
else
MIPS Instructions:
addi
slti
andi
ori
$29,
$8,
$29,
$29,
$29,
$18,
$29,
$29,
4
10
6
4
0000000000000000
ori
1010101010101010
0000000000000000
0000000000000000
1010101010101010
1010101010101010
1010101010101010
Instructions:
bne $t4,$t5,Label Next instruction is at Label if $t4 $t5
beq $t4,$t5,Label Next instruction is at Label if $t4 = $t5
j LabelNext instruction is at Label
Formats:
I
op
op
rs
rt
16 bit address
26 bit address
Addresses in Branches
Instructions:
bne $t4,$t5,Label
beq $t4,$t5,Label
op
rs
rt
16 bit address
To summarize:
To summarize:
Category
Arithmetic
Instruction
add
Example
add $s1, $s2, $s3
Meaning
$s1 = $s2 + $s3
subtract
Conditional
branch
Unconditional jump
$s1 = 100 * 2
16
Comments
branch on equal
beq
$s1, $s2, 25
if ($s1 == $s2) go to
PC + 4 + 100
bne
$s1, $s2, 25
if ($s1 != $s2) go to
PC + 4 + 100
slt
slti
jump
j
jr
jal
jump register
jump and link
else $s1 = 0
2500
$ra
2500
rs
rt
Immediate
2. Register addressing
op
rs
rt
rd
...
funct
Registers
Register
3. Base addressing
op
rs
rt
Memory
Address
Register
Byte
Halfword
4. PC-relative addressing
op
rs
rt
Memory
Address
PC
Word
5. Pseudodirect addressing
op
Address
PC
Memory
Word
Word
Complexity:
Saving grace:
Starting a program
Link
Starting a program
C program
compiler
Assembly program
assembler
Object program (user module)
linker
Executable
loader
Memory