|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Branch instructions |
|
|
|
|
Instruction |
|
Condition for branch (2C
values) |
|
|
beq $rs, $rt, offset |
# R[s] == R[t] |
|
|
|
|
bne $rs, $rt, offset |
# R[s] != R[t] |
|
|
|
|
bgtz $rs, offset |
|
# R[s] > 0 |
|
|
|
|
bgez $rs, offset |
|
# R[s] >= 0 |
|
|
|
|
bltz $rs, offset |
|
# R[s] < 0 |
|
|
|
|
blez $rs, offset |
|
# R[s] <= 0 |
|
|
|
|
|
Semantics: |
Addr = PC + (IR15)14 :: IR15-0 :: 00 |
compute branch address |
|
|
if ( condition ) |
|
test condition |
|
|
PC <-- Addr |
|
true: go to branch
address |
|
|
else |
|
|
|
|
PC <-- PC + 4 |
|
false: increment PC |
|
|
Don't use just 16 bits
for address: |
|
|
to next instruction |
|
|
|
Can assume 00, since all
addresses are word-aligned (like "hidden 1") |
|
|
But, we still don't want
to be limited to an 18-bit addresss |
|
|
How do most branches
occur? |
|
|
|
|
To an if or else block |
|
|
|
|
Back to top of loop |
|
|
|
Usually not very far
from current address (compared to entire 32-bit address range) |
|
|
|
Add offset to current PC
to get new address (PC relative addressing) |
|
|
Range |
PC - 217 to PC + 217 - 4 |
Why -4? |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|