Page 92 - ARM 64 Bit Assembly Language
P. 92

Load/store and branch instructions 77

                       Name     Effect                               Description
                       cbnz     if Rt  = 0 then                      Conditionally branch to label if Rt is
                                 pc ← label                          nonzero.
                                end if
                       tbz      if Rt[imm6] = 0 then                 Conditionally branch to label if the
                                 pc ← label                          specified bit in Rt is zero.
                                end if
                       tbnz     if Rt[imm6]  = 0 then                Conditionally branch to label if the
                                 pc ← label                          specified bit in Rt is nonzero.
                                end if



                     3.5.4.3 Examples

                     The following program reads one character at a time until it reads in a character with an odd
                     ASCII value. For example, it will stop when it reads ‘a’ or ‘c’, which have ASCII values 97
                     and 99 respectively. When it reads an odd ASCII value, it stops and prints out the character,
                     then returns zero to its caller:



                    1         .section .rodata
                    2  format: .string "You entered an odd char: %c.\n"
                    3         .text
                    4         .type  main, %function
                    5         .global main
                    6  main:
                    7         stp    x29, x30, [sp, #-16]!
                    8
                    9         // do{c= getchar(); } while (c % 2 == 0)
                   10  loop:
                   11         bl     getchar
                   12         tbz    x0, #0, loop
                   13
                   14         // printf("You entered an odd char: %c\n", c)
                   15         mov    x1, x0
                   16         ldr    x0, =format
                   17         bl     printf
                   18
                   19         // return 0
                   20         mov    w0, #0
                   21         ldp    x29, x30, [sp], #16
                   22         ret
                   23         .size  main, (. - main)
   87   88   89   90   91   92   93   94   95   96   97