Page 125 - ARM 64 Bit Assembly Language
P. 125

Data processing and other instructions 111

                      4.2. What will x0 and x1 contain after each of the following instructions? Give your an-
                           swers in base 10.

                          1         mov     x0,#1
                          2         mov     x1,#0x20
                          3         orr     x1,x1,x0
                          4         lsl     x1,x1,#0x2
                          5         orr     x1,x1,x0
                          6         eor     x0,x0,x1
                          7         lsr     x1,x0,#3
                      4.3. What is the difference between lsr and asr?
                      4.4. Write instructions to load the numbers stored at address num1 and address num2,add
                           them together, and store the result in numsum. Use only x0 and x1.
                      4.5. Given the following variable definitions:

                          1  num1:   .word   x
                          2  num2:   .word   y
                           where you do not know the values of x and y, write a short sequence of arm64 assem-
                           bly instructions to load the two numbers, compare them, and move the largest number
                           into register x0.
                      4.6. Assuming that a is stored in register x0 and b is stored in register x1, show the arm64
                           assembly code that is equivalent to the following C code:

                          1   if(a&1)
                          2     a = -a;
                          3   else
                          4     b=b+7;

                      4.7. Write a loop to count the number of bits in x0 that are set to 1. Use any other registers
                           that are necessary.
                      4.8. Without using any mul instruction, give the instructions to multiply x3 by the follow-
                           ing constants, leaving the result in x0.You mayalsouse x1 and x2 to hold temporary
                           results, and you do not need to preserve the original contents of x3.
                            a. 10
                            b. 100
                            c. 575
                            d. 123
                      4.9. Assume that x0 holds the least significant 64 bits of a 128-bit integer a,and x1 holds
                           the most significant 64 bits of a. Likewise, x2 holds the least significant 64 bits of a
                           128-bit integer b,and x3 holds the most significant 64 bits of b. Show the shortest in-
                           struction sequences necessary to:
                            a. compare a to b, setting the PSTATE flags,
   120   121   122   123   124   125   126   127   128   129   130