Page 102 - ARM 64 Bit Assembly Language
P. 102

88 Chapter 4

                    The following C program will add together two numbers stored in memory and print the
                                                        result.

                1  #include <stdio.h>
                2  static int x = 5;
                3  static int y = 8;
                4  int main(void)
                5  {
                6   int sum;
                7   sum=x+y;
                8   printf("The sum is %d\n",sum);
                9   return 0;
                10  }
                                  The equivalent AArch64 assembly program is as follows:

                1         .data
                2  fmt:   .asciz  "The sum is %d\n"
                3         .align  2
                4  x:     .word   5
                5  y:     .word   8
                6         .text
                7         .type   main, %function
                8         .global main
                9  main:
                10        stp     x29, x30, [sp, #-16]!  // Push FP and LR onto the stack
                11        // sum=x+y
                12        adr     x14, x                 // Calculate address of x
                13        adr     x15, y                 // Calculate address of y
                14        ldr     x4, [x14]              // Load x
                15        ldr     x5, [x15]              // Load y
                16        add     x1, x4, x5             // x1 = x4 + x5
                17
                18        // printf("The sum is %d\n", sum)
                19        adr     x0, fmt                // Calculate address of fmt
                20        bl      printf                 // Call the printf function
                21
                22        // return 0
                23        mov     w0, #0
                24        ldp     x29, x30, [sp], #16    // Pop FP and LR from the stack
                25        ret                            // Return from main
                26        .size   main,(. - main)



                  4.2.2 Logical operations

                  There are seven basic logical operations:
                  and     Bitwise AND,
   97   98   99   100   101   102   103   104   105   106   107