Page 121 - ARM 64 Bit Assembly Language
P. 121

Data processing and other instructions 107


                   16
                   17         // return 0
                   18         mov    w0, #0
                   19         ldp    x29, x30, [sp], #16
                   20         ret
                   21         .size  main, (. - main)


                     4.3.4 No operation

                     This instruction does nothing except waste execution time.

                     nop     No Operation.


                     4.3.4.1 Syntax
                          nop



                     4.3.4.2 Operations

                       Name     Effect                               Description
                       nop      No effects                           No Operation.


                     4.3.4.3 Examples

                     nop’s can sometimes be inserted to optimize machine specific code. Other times they are used
                     in computer attacks. They can even be used just to experiment with a debugger. The following
                     example shows how one might make a counter to delay a short period using nop instructions
                     and a loop:

                    1         .text
                    2         .type  main, %function
                    3         .global main
                    4  main:
                    5         // a programmed delay loop
                    6         mov    x0, #0x3fffffff // load loop counter
                    7  loop:  nop
                    8         nop
                    9         nop
                   10         nop
                   11         sub    x0, x0, #1      // decrement counter
                   12         cmp    w0, #0
                   13         bgt    loop
                   14         // return 0
   116   117   118   119   120   121   122   123   124   125   126