J Jump
Jal Jump and Link
Jr Jump Register
Jump:
Jumps to the target offset, a delay slot is needed.
Syntax:
J $Offset
Noop // This is the delay slot
Best used to call subroutines.
Jump and Link:
Executes the next line, then jumps to the target offset, then changes the return value (ra) value so it jumps to the offset after the delay slot.
Syntax:
Jal $Offset
Noop // Delay slot, so when the next line is executed nothing happens
{Now here is where the ra will jump to}
Best used for function calls because after the function is done it will return to the offset after the noop.
Jump Register:
Jumps to the offset stored in a register. A delay slot is needed.
Syntax:
Lui t0, $0880 // Loads 0880 into t0, now t0 holds the offse 08800000
Jr t0 // Jumps to the offset 08800000
Noop
Now if you are confused why we didn't do this to load the offset:
Lui t0, $0880
Lw t0, $0000(t0)
Is because the LUI command loads 16 bits into a register and the right 16Bits are zeros. So lui t0, $0880 will load the offset 08800000 into the register t0
So the syntax will jump to the offset 08800000
Tips for these commands:
Use J for calling subroutines
Use Jal for calling functions
Use Jr for ending a subroutine by jumping to the return address (ra)
Always use a delay slot (A noop on the next offset) when using Jump commands
END TUTORIAL
1 reply to this topic
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









