Page 75 - ARM 64 Bit Assembly Language
P. 75
60 Chapter 3
3.3.2 Immediate values
An immediate value in assembly language is a constant value that is specified by the program-
mer. Some assembly languages encode the immediate value as part of the instruction. Other
assembly languages create a table of immediate values in a literal pool,storedinmemory,and
insert appropriate instructions to access them. ARM assembly language provides both meth-
ods.
Immediate values can be specified in decimal, octal, hexadecimal, or binary. Octal values
must begin with a zero, and hexadecimal values must begin with “0x”. Likewise immediate
values that start with “0b” are interpreted as binary numbers. Any value that does not begin
with zero, 0x,or 0b will be interpreted as a decimal value.
There are two ways that immediate values can be specified in GNU ARM assembly. The first
way is as a literal immediate value. This can be optionally prefixed with a pound sign for clar-
ity: #<immediate|symbol>. The second way is the =<immediate|symbol> syntax, which
can only be used with the ldr pseudo-instruction. The =<immediate|symbol> syntax can
be used to specify any immediate value (up to 64-bits), or to specify the 64-bit value of any
symbol in the program. Symbols include program labels (such as main) and symbols that
are defined using .equ and similar assembler directives. This syntax is a pseudo-instruction
because of the way the AArch64 machine instructions are encoded. For data processing in-
structions, there are a limited number of bits that can be devoted to storing immediate data as
part of the instruction. In order to store a full 64-bit immediate, the linker must create a literal
pool.
The #<immediate|symbol> syntax is used to specify immediate data values for data pro-
cessing instructions. The #<immediate|symbol> syntax has some restrictions. The assem-
bler must be able to construct the specified value using only a certain number of bits of data,
a shift or rotate, and/or a complement. For example, arithmetic immediate instructions can
only use an immediate value that fits within 12 bits. For immediate values that can cannot be
constructed by shifting or rotating and complementing an 12-bit value, the programmer must
use an ldr instruction with the =<immediate|symbol> to specify the value. That method is
covered in Section 3.4.
Some examples of immediate values are shown in Table 3.3. When an immediate value is nec-
essary, the programmer can always use the #<immediate|symbol> syntax. The assembler
will emit an error message when an invalid immediate value is attempted, and the programmer
can change their code to use the ldr Rx,=<immediate|symbol> method instead.