Page 21 - ARM 64 Bit Assembly Language
P. 21

4Chapter 1

                  were designed for, they do not optimize well. Many newer CPUs have instructions which op-
                  erate on multiple items of data at once. However, compilers rarely make use of these powerful
                  Single Instruction Multiple Data (SIMD) instructions. Instead, it is common for programmers
                  to write functions in assembly language to take advantage of SIMD instructions. The assem-
                  bly functions are assembled into object file(s), then linked with the object file(s) generated
                  from the high-level language compiler.

                  Many modern processors also have some support for processing vectors (arrays). Compil-
                  ers are usually not very good at making effective use of the vector instructions. In order to
                  achieve excellent vector performance for audio or video codecs and other time-critical code, it
                  is often necessary to resort to small pieces of assembly code in the performance-critical inner
                  loops. A good example of this type of code is when performing vector and matrix multiplies.
                  Such operations are commonly needed in processing images and in graphical applications.
                  The vector instructions are explained in Chapter 10.

                  Another reason for assembly is when writing certain parts of an operating system. Although
                  modern operating systems are mostly written in high-level languages, there are some portions
                  of the code that can only be done in assembly. Typical uses of assembly language are when
                  writing device drivers, saving the state of a running program so that another program can use
                  the CPU, restoring the saved state of a running program so that it can resume executing, and
                  managing memory and memory protection hardware. There are many other tasks that are cen-
                  tral to a modern operating system which can only be accomplished in assembly language.
                  Careful design of the operating system can minimize the amount of assembly required, but
                  cannot eliminate it completely.
                  Another good reason to learn assembly is for debugging. Simply understanding what is go-
                  ing on at a fundamental level can be very valuable when trying to debug programs. If there
                  is a problem in a call to a third party library, sometimes the only way a developer can iso-
                  late and diagnose the problem is to run the program under a debugger and step through it one
                  machine instruction at a time. This does not require a deep knowledge of assembly language
                  coding but at least a passing familiarity with assembly is helpful in that particular case. Anal-
                  ysis of assembly code is an important skill for C programmers and C++ programmers, who
                  may occasionally have to diagnose a fault by looking at the contents of CPU registers and
                  single-stepping through machine instructions.

                  Assembly language is an important part of the path to understanding how the machine works.
                  Even though only a small percentage of computer scientists will be lucky enough to work on
                  the code generator of a compiler, they all can benefit from the deeper level of understanding
                  that they gain by learning assembly language. Many programmers do not really understand
                  pointers until they have written assembly language.
   16   17   18   19   20   21   22   23   24   25   26