SME
Computer Organization & Architecture · Problem type
Branch target address
Use this for “A MIPS beq at 0x00400020 has offset 3. Where does the branch go if it is taken?”
This is an example. Type your own values to start a new problem.
ISA
Instruction set
example
PC
Branch address
example
offset
Offset
example
d
Bytes jumped
worked out (not typed)
T
Target address
calculated
Formulas
d
=
4
+
4
×
offset
16 = 4 + 4 × 3
T
=
PC
+
d
0x00400030 = 0x00400020 + 16
Assumptions
•
Instructions are 4 bytes and addresses count bytes, so the branch address (PC) is a multiple of 4.
•
MIPS: the offset counts instructions from the next one, so the target is PC + 4 + 4 × offset.
•
RISC-V: the offset counts bytes from the branch itself, is even and lies from −4,096 to 4,094.
Step-by-step
WE KNOW
ISA: MIPS, PC = 0x00400020, offset = 3
FIND
bytes jumped (d), target address (T)
Step 1 · Find bytes jumped (d)
Use d = 4 + 4 × offset
MIPS counts from the next instruction, 4 bytes on, in steps of 4 bytes.
MIPS: the offset counts instructions from the next one
d
=
4
+
4
×
3
d
=
4
+
12
d
=
16
Step 2 · Find target address (T)
Use T = PC + d
Add the bytes jumped to the branch address.
T
=
0x00400020
+
16
T
=
0x00400030
Check
Put the numbers back in. Both sides should match.
16 = 4 + 4 × 3 ✓
0x00400030 = 0x00400020 + 16 ✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.