Jump Instructions
Jump instructions use direct mode addressing
If you look at "j place", it looks like a branch without the registers
However, where place would be PC-relative mode in the branch, it is direct mode in the jump
.text
add $11 $12 $13 # 0x00400000 is the address of this instruction
j place # 0x00400004
add $11 $12 $13 # 0x00400008
add $11 $12 $13 # 0x0040000C
add $11 $12 $13 # 0x00400010
add $11 $12 $13 # 0x00400014
place: add $11 $12 $13 # 0x00400018
- Here's some code with the addresses that it assembles to
- Here's what it looks like boxed up
- The times-4 trick is in play here so the value in the address box is 0x00400018 ÷ 4
Can we convince ourselves that 0x00400018 ÷ 4 really is 0x00100006 ?
- Write 0x00400018 out in binary:
- 0000 0000 0100 0000 0000 0000 0001 1000
- Now shift it 2 places to the right:
- 0000 0000 0100 0000 0000 0000 0001 10
- regrouped, that looks like this:
- 0000 0000 0001 0000 0000 0000 0000 0110
- There you go
- Or copy the code, paste it into MARS, and assemble it
- The jump instruction will assemble to 0x08100006
- While you're in MARS, comment out the very first instruction and assemble it again
- Now the jump instruction will assemble to 0x08100005
- Notice that the distance between the jump and its target did not change
- The value in the address field of the jump changed because the absolute address of the target
changed from 0x00400018 to 0x00400014
- Here's another way to see that 0x00400014 ÷ 4 is 0x00100005