Various Branch Instructions
Various Branch Instructions
label
f = i + j; break;
case 1:
f = g + h; break;
case 2:
f = g h; break;
case 3:
f = i j; break;
# if k 4 the Exit
Exit:
What next? Jump to the right case!
Base address
of the
jumptable
32-bit address L0
32-bit address L1
32-bit address L2
32-bit address L3
L0
f=i+j
J Exit
L1
f = g+h
j Exit
Exit
MEMORY
jumptable
register $t4
# t1 = 2*k
# t1 = 4*k
lw $t0, 0($t1)
jr $t0
L0: add $s0, $s3, $s4
J Exit
L1: add $s0, $s1, $s2
# f = g+h
J Exit
L2: sub $s0, $s1, $s2
# f = g-h
J Exit
L3: sub $s0, $s3, $s4
Exit: <next instruction>
#f=i-j
10000
is represented as
2500
6-bits
This is the
26 bits
16
17
is represented as
16-bit offset
What does
this program
do?
$t0, 0($t1)
Loop
80000
19
19
32
R-type
80004
32
R-type
80008
22
32
R-type
80012
35
I-type
80016
21
2 (why?)
I-type
80020
19
20
R-type
80024
Exit:
80028
19
32
20000 (why?)
Machine
language
version
J-type
Addressing Modes
Register addressing
Operand is in register
add $s1, $s2, $s3 means
Base addressing
Operand is in memory.
The address is the sum of a register and a constant.
lw $s1, 32($s3) means
Direct addressing
$s1 M[32]
Indirect addressing
$s1 M[s3]
Immediate addressing
The operand is a constant.
How can you execute
$s1 7?
PC-relative addressing
The operand address = PC + an offset
Implements position-independent codes. A small
offset is adequate for short loops.
Pseudo-direct addressing
Used in the J format. The target address is the
concatenation of the 4 MSBs of the PC with the 28-bit
offset. This is a minor variation of the PC-relative
addressing format.