Immediate values are constants used as operands. They can be specified in decimal, octal (03), hexadecimal (0x2F), or binary (0b11010010).
There are two distinct syntaxes in GNU assembly depending on the instruction type:
- For Load/Store instructions: Use
=<immediate|symbol>. This specifies a 32-bit immediate value or the value of a symbol (label or .equ). - For Data-processing instructions: Use
#<immediate|symbol>.
Important Restrictions:
- The
= syntax is only for load/store instructions. - The
# syntax is restricted: the assembler must be able to construct the value using only eight bits of data, a shift/rotate operation, and/or a complement. If a value cannot meet these constraints, you must use a ldr instruction with the = syntax to load it from a literal pool.
; Example of using the = syntax for load/store
LDR R0, =0x12345678
; Example of using the # syntax for data processing
ADD R1, R2, #5