Page 128 - ARM 64 Bit Assembly Language
P. 128

114 Chapter 5


                                             Listing 5.1 if statement in C.
                           .
                1          . .
                2   if (x >= y)
                3   {
                           .
                4          . .                   // if statement body
                5   }
                           .
                6          . .


                  is extremely difficult to debug. If the flow of control is too complex for the programmer to fol-
                  low, then it cannot be adequately debugged. It is the responsibility of the assembly language
                  programmer to write code that uses a block-structured approach.

                  Adherence to structured programming principles results in code that has a much higher prob-
                  ability of working correctly. Also, well-written code has fewer branch statements. Therefore,
                  the ratio of data processing statements versus branch statements is higher. High data process-
                  ing density results in higher throughput of data. In other words, writing code in a structured
                  manner leads to higher efficiency.



                  5.1 Sequencing

                  Sequencing simply means executing statements (or instructions) in a linear sequence. When
                  statement n is completed, statement n + 1 will be executed next. Uninterrupted sequences of
                  statements form basic blocks. Basic blocks have exactly one entry point and one exit point.
                  Flow control is used to select which basic block should be executed next.



                  5.2 Selection

                  The first control structure that we will examine is the basic selection construct. It is called
                  selection because it selects one of two (or possibly more) blocks of code to execute, based
                  on some condition. In its most general form, the condition could be computed in a variety
                  of ways, but most commonly it is the result of some comparison operation or the result of
                  evaluating a Boolean expression.


                  5.2.1 If-then statement

                  The most important form of selection is the if statement. Listing 5.1 demonstrates a simple
                  if statement in C. Listing 5.2 shows the AArch64 assembly translation. The first label is for
   123   124   125   126   127   128   129   130   131   132   133