Page 87 - ARM 64 Bit Assembly Language
P. 87

72 Chapter 3


                11        mov     w0, #1
                12  endif1:
                13
                14        // return w0
                15        ldp     x29, x30, [sp], #16
                16        ret


                  3.5.2 Branch register

                  These instructions allow the program counter to be set to the value contained in a 64-bit
                  general-purpose register (x0-x30):

                  br    Branch to Register and
                  ret   Return from Subroutine.


                  3.5.2.1 Syntax

                       br       Xn
                       ret      {Xn}


                  •  ret uses the procedure link register (LR), which is x30, if no register is specified.
                  •  ret is only used to return from a subroutine.
                  •  br can be used for implementing a computed goto (switch statement).

                  3.5.2.2 Operations

                   Name     Effect                               Description
                   br       pc ← Xn                              Copy register Xn to the program
                                                                 counter (pc).
                   ret      pc ← X30 or pc ← Xn                  Copy the link register (X30), or any
                                                                 other register (Xn) to the program
                                                                 counter (pc).

                  3.5.2.3 Examples

                  The branch register instruction will set the pc register to the contents of a register:

                1         br      x10
                  This can generate a Segmentation Fault if the contents of x10 are invalid. If not, the processor
                  will begin executing instructions at the address contained in x10.
   82   83   84   85   86   87   88   89   90   91   92