Jmp | : Pc = Register |
Jsr | : Stack <- Pc ; Pc = Register |
Bra | : Pc = Pc + Immediate16Bits |
Rts | : Stack -> PC |
Rti | : Stack -> StatusRegister ; Stack->Pc |
Affected Flags (jmp,jsr, bra,rts) |
|||
C | V | N | Z |
All these instructions are related to changing the path of execution or calling subroutine. The Jmp instructions causes a direct jump to the specified location. The Jsr instruction is made to call subroutines : it does the same thing as the Jmp instruction but the address following the Jsr instruction is stored in the stack, so an Rts instruction at the end of the subroutine will cause resuming the execution just after the Jsr instruction.
Affected Flags (rti) |
|||
C | V | N | Z |
X | X | X | X |
rx = Register containing the destination address
Form | Effect |
jmp (rx) |
Jump to location Pc <- Rx |
jsr (rx) |
Call subroutine Stack <- Pc Pc <- Rx |
bra #label |
Jump to location (relative) Pc = Pc + 16BitsSignedImmediate |
Rts | Return from subroutine (called with jsr) Pc <- Stack |
Rti | Return from interrupt StatusRegister <- Stack Pc <- Stack |
I = Immediate 16 bit value of the relative jump
D = Register number
Instruction | Op Code |
Cycles | Encoding |
jmp (rx) | 1B | 6 | 00011011 0000DDDD |
jsr (rx) | 5B | 14 | 01011011 0000DDDD |
bra #16BitsSignedValue | 60 | 8 | 01100000 IIIIIIII IIIIIIII |
rts | 9B | 12 | 10011011 |
rti | DB | 16 | 11011011 |
Note: This example is for understanding and can be optimized.
// Example : Calling a subroutine
start: move.l #123456,r0 ; Argument 1
move.l #356464,r1 ; Argument 2
move.l #subroutine, r2 ; Address of subroutine
jsr (r2) ; Call subroutine
brk ; end of the program
subroutine:add.l r1,r0 ; doing the subroutine function
rts ; return