Page 19 - ARM 64 Bit Assembly Language
P. 19

2Chapter 1

                  The CPU also contains a much smaller set of mailboxes, which we call registers. Data can
                  be copied from cards stored in memory to cards stored in the CPU, or vice-versa. Once data
                  has been moved into one of the CPU registers, it can be used in computation. For example, in
                  order to add two numbers in memory, they must first be moved into registers on the CPU. The
                  CPU can then add the numbers together and store the result in one of the CPU registers. The
                  result of the addition can then be moved back into one of the mailboxes in memory.

                  Modern computers execute instructions sequentially. In other words, the next instruction to
                  be executed is at the memory address immediately following the current instruction. One of
                  the registers in the CPU, the program counter (PC) keeps track of the location from which
                  the next instruction is to be fetched. The CPU follows a very simple sequence of actions. It
                  fetches an instruction from memory, increments the program counter, executes the instruction,
                  and then repeats the process with the next instruction. However some instructions may change
                  the program counter, so that the next instruction is fetched from a non-sequential address.



                  1.1 Reasons to learn assembly

                  There are many high-level programming languages, such as Java, Python, C, and C++ that
                  have been designed to allow programmers to work at a high level of abstraction, so that they
                  do not need to understand exactly what instructions are needed by a particular CPU. For com-
                  piled languages, such as C and C++, a compiler handles the task of translating the program,
                  written in a high-level language into assembly language for the particular CPU on the system.
                  An assembler then converts the program from assembly language into the binary codes that
                  the CPU reads as instructions.
                  High-level languages can greatly enhance programmer productivity. However, there are some
                  situations where writing assembly code directly is desirable or necessary. For example, as-
                  sembly language may be the best choice when writing

                  •  the first steps in booting the computer,
                  •  code to handle interrupts,
                  •  low-level locking code for multi-threaded programs,
                  •  code for machines where no compiler exists,
                  •  in situations where the compiler cannot generate code that is optimal (or efficient
                     enough),
                  •  on computers with very limited memory, and
                  •  code that requires low-level access to architectural and/or processor features.
                  Aside from sheer necessity, there are several other reasons why it is still important for com-
                  puter scientists to learn assembly language.
   14   15   16   17   18   19   20   21   22   23   24