Sidan 1
Computer Engineering BranchProcCall page 1
3 + 5 + 7
Addiu $t1 $r0 3 Addiu $t1 $t1 5 Addiu $t1 $t1 7
Example
Computer Engineering BranchProcCall page 2
La $t0 tal Lw $t1 0($t0) Lw $t2 4($t0) Lw $t3 8($t0) Addu $t4 $t1 $t2 Addu $t4 $t4 $t3 Sw $t4 12($t0) 3 5 7 tal
Example 2
Computer Engineering BranchProcCall page 3
The Branch Instruction
■ B label ■ “label” is an instruction address. ■ Instruction addresses are 32 bits. ■ But branch instructions are
immediate format, ONLY 16 BITS !?
Computer Engineering BranchProcCall page 4
How It’s Done!
x B z x, y, z all have y ! absolute values. ! ! But the quantity z ! z - y is an offset ! (a relative value).
■ If the offset z - y can be represented in
16 bits, then it will fit.
Computer Engineering BranchProcCall page 5
But There’s One More Trick....
■ z and y are valid byte addresses, both word aligned! ■ That means that:
z = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx00 y = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx00
so
z - y = xxxxxxxxxxxxxx00
■ Why waste space representing two
bits which are always zero?
Computer Engineering BranchProcCall page 6
But there’s one more trick....
■ So, shift the difference (z - y) right two bits. ■ That way, if (z - y) fits in 18 bits we can save the
- ffset in 16 bits!