Computer Architecture: MIPS Instruction Set Architecture
Computer Architecture: MIPS Instruction Set Architecture
Operations ≡ Instructions
Memory Memory
63 63
··
··
Registers 24 (j 15) Registers 24 (j 15)
(beq r0, r1, 2) (beq r0, r1, 2)
r3 8 23 add r1, r2, r3 r3 8 23
22 (sw r3, 0(r0)) 22 (sw r3, 0(r0))
r2 12 r2 12
21 (lw r2, 1(r0)) 21 (lw r2, 1(r0))
r1 1 r1 20
r0 2 20 (add r1, r2, r3) r0 2 20 (add r1, r2, r3)
··
··
PC 20 PC 21
3 7 3 7
2 2 2 2
1 0 1 0
0 4 0 4
Memory Memory
63 63
··
··
Registers 24 (j 15) Registers 24 (j 15)
(beq r0, r1, 2) (beq r0, r1, 2)
r3 8 23 lw r2, 1(r0) r3 8 23
22 (sw r3, 0(r0)) 22 (sw r3, 0(r0))
r2 12 r2 7
21 (lw r2, 1(r0)) 21 (lw r2, 1(r0))
r1 20 r1 20
r0 2 20 (add r1, r2, r3) r0 2 20 (add r1, r2, r3)
··
··
PC 21 PC 22
3 7 3 7
2 2 2 2
1 0 1 0
0 4 0 4
Memory Memory
63 63
··
··
Registers 24 (j 15) Registers 24 (j 15)
(beq r0, r1, 2) (beq r0, r1, 2)
r3 8 23 sw r3, 0(r0) r3 8 23
22 (sw r3, 0(r0)) 22 (sw r3, 0(r0))
r2 7 r2 7
21 (lw r2, 1(r0)) 21 (lw r2, 1(r0))
r1 20 r1 20
r0 2 20 (add r1, r2, r3) r0 2 20 (add r1, r2, r3)
··
··
PC 22 PC 23
3 7 3 7
2 2 2 8
1 0 1 0
0 4 0 4
Memory Memory
63 63
··
··
Registers 24 (j 15) Registers 24 (j 15)
(beq r0, r1, 2) (beq r0, r1, 2)
r3 8 23 beq r0, r1, 2 r3 8 23
22 (sw r3, 0(r0)) 22 (sw r3, 0(r0))
r2 7 r2 7
21 (lw r2, 1(r0)) 21 (lw r2, 1(r0))
r1 20 r1 20
r0 2 20 (add r1, r2, r3) r0 2 20 (add r1, r2, r3)
··
··
PC 23 PC 24
3 7 3 7
2 8 2 8
1 0 1 0
0 4 0 4
Memory Memory
63 63
··
··
Registers 24 (j 15) Registers 24 (j 15)
(beq r0, r1, 2) (beq r0, r1, 2)
r3 8 23 j 15 r3 8 23
22 (sw r3, 0(r0)) 22 (sw r3, 0(r0))
r2 7 r2 7
21 (lw r2, 1(r0)) 21 (lw r2, 1(r0))
r1 20 r1 20
r0 0 20 (add r1, r2, r3) r0 0 20 (add r1, r2, r3)
··
··
PC 24 PC 15
3 7 3 7
2 8 2 8
1 0 1 0
0 4 0 4
From “Single-Chip Multiprocessors: the Rebirth of Parallel Architecture” by Prof. Guri Sohi
Source: www.icknowledge.com
Co-processors
Superscalar
etc
From “Single-Chip Multiprocessors: the Rebirth of Parallel Architecture” by Prof. Guri Sohi
Register Memory
0xffff ffff
$31
$1 30
$0 0 2 words =
32
PC 2 bytes
LO
HI
0x0000 0000
6 $a2 27 $k1
7 $a3 28 $gp global pointer
Arithmetic/Logic instructions
Data Transfer (Load/Store) instructions
Conditional branch instructions
Unconditional jump instructions
Field size 6bits 5bits 5bits 5bits 5bits 6bits All MIPS insturctions 32 bits
R-format op rs rt rd shamt funct Arithmetic instruction format
I-format op rs rt address/immediate Transfer, branch, imm. format
J-format op target address Jump instruction format
Logical and and $s1, $s2, $s3 $s1 = $s2 & $s3 Thee reg. operands; bit-by-bit AND
and immediate andi $s1, $s2, 100 $s1 = $s2 & 100 Bit-by-Bit AND reg with constant
or or $s1, $s2, $s3 $s1 = $s2 | $s3 Thee reg. operands; bit-by-bit OR
or immediate ori $s1, $s2, 100 $s1 = $s2 | 100 Bit-by-Bit OR reg with constant
xor xor $s1, $s2, $s3 $s1 = $s2 xor $s3 Logical XOR
xor immediate xori $s1, $s2, 10 $s1 = $s2 xor 10 Logical XOR w/ constant
nor nor $s1, $s2, $s3 $s1 = ┒($s2 ∨ $s3) Logical NOR
shift left logical sll $s1, $s2, 10 $s1 = $s2 ≪ 10 Shift left by constant
shift right logical srl $s1, $s2, 10 $s1 = $s2 ≫ 10 Shift right by constant
shift right arithmetic sra $s1, $s2, 10 $s1 = $s2 ≫ 10 Shift right (sign extended)
shift left logical variable sllv $s1, $s2, $s3 $s1 = $s2 ≪ $s3 Shift left by variable
shift right logical variable srlv $s1, $s2, $s3 $s1 = $s2 ≫ $s3 Shift right by variable
shift right arithmetic variable srav $s1, $s2, $s3 $s1 = $s2 ≫ $s3 Shift right arithmetic by variable
load upper immediate lui $s1, 40 $s1 = 40 ≪ 16 Places immediate into upper 16 bits
Date store word sw $ s1, 100($ s2) Memory[$ s2 + 100] = $ s1 Word from register to memory
transfer store halfword sh $ s1, 100($ s2) Memory[$ s2 + 100] = $ s1 Store only lower 16 bits
store byte sb $ s1, 100($ s2) Memory[$ s2 + 100] = $ s1 Store only lowest byte
store float swc1$ f1,100($ s2) Memory[$ s2 + 100] = $ f1 Store FP word
load word lw $ s1, 100($ s2) $ s1 = Memory[$ s2 + 100] Load word
load halfword lh $ s1, 100($ s2) $ s1 = Memory[$ s2 + 100] Load halfword; sign extended
load half unsigned lhu $ s1, 100($ s2) $ s1 = Memory[$ s2 + 100] Load halfword; zero extended
load byte lb $ s1, 100($ s2) $ s1 = Memory[$ s2 + 100] Load byte; sign extended
load byte unsigned lbu $ s1, 100($ s2) $ s1 = Memory[$ s2 + 100] Load byte; zero extended
load float lwc1 $ f1,100($ s2) $ f1 = Memory[$ s2 + 100] Load FP register
load upper immediate lui $ s1, 100 16 Loads constant in upper 16 bits
$ s1 = 100 * 2
a b c d ( at address 20 )
MSB LSB
23 d 23 a
22 c 22 b
21 b 21 c
20 a 20 d
conditional branch branch on equal beq $ s1, $ s2, L if($ s1==$ s2) go to L Equal test and branch
branch on not equal bne $ s1, $ s2, L if($ s1!=$ s2) go to L Not equal test and branch
Operand in register
Register addressing
op rs rt rd ··· funct Registers
Register
Operand in Memory
Base addressing
Memory
op rs rt Address
Instruction in memory
PC-relative addressing (branch)
op rs rt Address Memory
+ Word
PC
op Address Memory
: Word
4bits PC
Instruction in memory
Register (jump register)
op rs Memory
Register Word
C Assembly
f = (g + h) – (i + j);
add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1
f is mapped to s0
g is mapped to s1
h is mapped to s2
i is mapped to s3
j is mapped to s4
C Assembly
g = h + A[i];
add $t1, $s4, $s4
add $t1, $t1, $t1
add $t1, $t1, $s3
g is mapped to s1 lw $t0, 0($t1)
h is mapped to s2 add $s1, $s2, $t0
s3 contains the base
address of array A[].
i is mapped to s4.
C Assembly
if (i == j) bne $s3, $s4, Else
f = g + h; add $s0, $s1, $s2
else j Exit
f = g – h; Else: sub $s0, $s1, $s2
Exit:
f is mapped to s0
g is mapped to s1
h is mapped to s2
i is mapped to s3
j is mapped to s4
C Assembly
Loop: add $t1, $s3, $s3
while (save[i] == k) add $t1, $t1, $t1
i = i + j; add $t1, $t1, $s6
lw $t0, 0($t1)
bne $t0, $s5, Exit
add $s3, $s3, $s4
i is mapped to s3 j Loop
j is mapped to s4 Exit:
k is mapped to s5
s6 contains the base address
of array save[].
C Assembly
slt $t3, $s5, $zero
switch (k) {
bne $t3, $zero, Exit
case 0: f = i + j; break; slt $t3, $s5, $t2
case 1: f = g + h; break; beq $t3, $zero, Exit
case 2: f = g - h; break; add $t1, $s5, $s5
case 3: f = i - j; break; add $t1, $t1, $t1
} add $t1, $t1, $t4
lw $t0, 0($t1)
jr $t0
f is mapped to s0 L0: add $s0, $s3, $s4
g is mapped to s1 j Exit
h is mapped to s2 L1: add $s0, $s1, $s2
j Exit
i is mapped to s3
L2: sub $s0, $s1, $s2
j is mapped to s4 j Exit
k is mapped to s5 L3: sub $s0, $s3, $s4
t2 contains 4 Exit