Intranet Catprocess
  1. news...
  2. about Blackvoxel
  3. download
  4. manual
  5. videos
  6. about us
  1. Jmp/Jsr/Bra/Rts/Rti - Unconditionnal jumps, subroutine call and return

    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
    The Bra instruction is like Jmp but instead of absolute register addressing mode, Bra uses relative immediate addressing mode like all Bxx instructions.
    The Rti instruction mean "return from interrupt". This instruction must be used to terminate an interrupt function and resume the regular program execution flow. Compared to the Rts instruction, the Rti instruction will also restore the status register from the stack. This is the only instruction to affect the status flags.

    Forms and variants

    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

    Instruction encoding

    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

    Code Examples

    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
               
     
     
  2. Google+