Page 114 - ARM 64 Bit Assembly Language
P. 114

100 Chapter 4


                5   do
                6     {}                     // loop body does nothing
                7   while (getchar() != ’A’)
                8   return 0;
                9  }

                  An AArch64 translation of the C program uses the cmp instruction to test whether or not the
                  input character is ‘A’ and a conditional branch instruction to implement the do-while loop:

                1         .text
                2         .type   main, %function
                3         .global main
                4  main:
                5         stp     x29, x30, [sp, #-32]!
                6         str     x19, [sp, #16]
                7         mov     x19, #’A’
                8
                9  loop:  // beginning of do-while loop
                10
                11        // loop body does nothing
                12
                13        bl      getchar       // call getchar to get next character in x0
                14        cmp     x0, x19       // compare it to ’A’
                15        bne     loop          // repeat loop if the character is not equal to ’A’
                16
                17        ldr     x20, [sp, #16]
                18        ldp     x29, x30, [sp], #32
                19        ret
                20        .size   main, (. - main)


                  4.2.10 Conditional operations


                  These conditional select operations set the destination register to the first operand, Rn if the
                  condition is true, and to the second operand optionally incremented, inverted, or negated if the
                  condition is false:

                  csel    Conditional Select,
                  csinc   Conditional Select Increment,
                  csinv   Conditional Select Invert,
                  csneg   Conditional Select Negate.

                  There are five aliases that are derived from the previous instructions:
                  cinc    Conditional Increment,
                  cinv    Conditional Invert,
   109   110   111   112   113   114   115   116   117   118   119