Unformatted text preview: constant "J" (alternative syntax) –5– Of course, a good programmer will define a symbol with the appropriate value and
use that instead:
.set letter_J, 'J'
mov r0, #letter_J ; This is a contrived example! Character constants can also contain certain backslash escape sequences, similar to
the C programming language. See section 3.6.1 of the GNU Assembler Reference for
Apart from simple integer numbers, expressions can also look like standard mathematical and logical expressions expressed in the C language. These are described in
detail in Chapter 6 of the GNU Assembler Reference. Some examples are:
bm1, 128 * 1024
; 131072 bytes (128KB)
start_ROM + ROMsize ; 0xE0020000
; Binary bit-mask (hex 0xCD) .set
.set val1, -2 * 4 + (45 / (5 << 2)) ; -6 (in two's complement)
val2, ROM_size >> 10
; 128 (131072 shifted right by 10)
val3, bm1 | 0b11110000
; bm1 OR 0b11110000 = 0b11111101 Expressions can, of course, contain previously-defined labels, as illustrated above.
Such expressions can yield absolute values or relative values. Absolute values don’t
depend on their position in the final executable (ie, they are position-independent);
they are a simple numeric constant, such as those in the examples above. Relative
values, on the other hand, are relative to some address, such as the start of the .data
section. These values are only fixed into place (ie, assigned a value) by the linker
when the final executable is created, not by the assembler.
Relative values are mainly used for offset calculations, and can only use the “+” and
“-” operators. For example:
.set ; Many assembly language instructions... instr_size,
; instructions are all 4 bytes long on ARM
code_end - code_start
code_start + 10 * instr_size
instr_11th - instr_size The symbol code_length is set to an abs...
View Full Document
- Assembly Language, GNU Assembler, GNU Assembler Reference