Hardware Reference
In-Depth Information
all, an expert assembly language programmer working very hard can sometimes
produce code that is much smaller and much faster than a high-level language pro-
grammer can. For some applications, speed and size are critical. Many embedded
applications, such as the code on a smart card or RFID card, device drivers, string-
manipulation libraries, BIOS routines, and the inner loops of performance-critical
real-time applications fall in this category.
Second, some procedures need complete access to the hardware, something
usually impossible in high-level languages. For example, the low-level interrupt
and trap handlers in an operating system and the device controllers in many em-
bedded real-time systems fall into this category.
Besides these reasons for programming in assembly language, there are also
two additional reasons for studying it. First, a compiler must either produce output
used by an assembler or perform the assembly process itself. Thus understanding
assembly language is essential to understanding how compilers work. Someone
has to write the compiler (and its assembler) after all.
Second, studying assembly language exposes the real machine to view. For
students of computer architecture, writing some assembly code is the only way to
get a feel for what a machine is really like at the architectural level.
7.1.3 Format of an Assembly Language Statement
Although the structure of an assembly language statement closely mirrors the
structure of the machine instruction that it represents, assembly languages for dif-
ferent machines sufficiently resemble one another to allow a discussion of assem-
bly language in general. Figure 7-1 shows fragments of assembly language pro-
grams for the x86 which performs the computation N
J . The statements
below the blank line are commands to the assembler to reserve memory for the
variables I , J , and N and are not symbolic representations of machine instructions.
=
I
+
Label
Opcode
Operands
Comments
FORMULA: MOV
EAX,I
; register EAX = I
ADD
EAX,J
; register EAX=I+J
MOV
N,EAX
;N=I+J
I
DD
3
; reserve 4 bytes initialized to 3
J
DD
4
; reserve 4 bytes initialized to 4
N
DD
0
; reserve 4 bytes initialized to 0
Figure 7-1. Computation of N =
I
+ J on the x86.
Several assemblers exist for the Intel family (i.e., x86), each with a different
syntax. In this chapter we will use the Microsoft MASM assembly language for
our example. There are many assemblers for the ARM, but the syntax is compara-
ble to the x86 assembler, so one example should siffice.
 
 
Search WWH ::




Custom Search