Page 66 - ARM 64 Bit Assembly Language
P. 66

50 Chapter 2

                   2.5. What is the total memory, in bytes, allocated for the following variables?

                      1  var1:  .word   23
                      2  var2:  .long   0xC
                      3  expr:  .ascii  ">>"
                   2.6. Identify the directive(s), label(s), comment(s), and instruction(s) in the following code:

                      1         .text
                      2         .global main
                      3  main:
                      4         mov     w0,#1   // the program return code is 1
                      5         ret             // return and exit the program
                   2.7. Write assembly code to declare variables equivalent to the following C code:

                      1  /* these variables are declared outside of any function */
                      2  static int foo[3];  /* visible anywhere in the current file */
                      3  static char bar[4];  /* visible anywhere in the current file */
                      4  char barfoo;        /* visible anywhere in the program */
                      5  int foobar;         /* visible anywhere in the program */
                   2.8. Show how to store the following text as a single string in assembly language, while
                        making it readable and keeping each line shorter than 80 characters:
                            The three goals of the mission are:
                            1) Keep each line of code under 80 characters,
                            2) Write readable comments,
                            3) Learn a valuable skill for readability.
                   2.9. Insert the minimum number of .align directives necessary in the following code
                        so that all double-word variables are aligned on double-word boundaries, all word
                        variables are aligned on word boundaries, and all halfword variables are aligned on
                        halfword boundaries, while minimizing the amount of wasted space.

                      1         .data
                      2  a:     .byte   7
                      3  b:     .word   32
                      4  c:     .byte   7
                      5  d:     .quad   0x1234567890abcdef
                      6  e:     .byte   7
                      7  f:     .hword  0xffff

                  2.10. Re-order the directives in the previous problem so that no .align directives are nec-
                        essary to ensure proper alignment. How many bytes of storage were wasted by the
                        original ordering of directives, compared to the new one?
                  2.11. What are the most important directives for selecting a section?
   61   62   63   64   65   66   67   68   69   70   71