As well as the use of literals as arguments and their definition as constants with EQU as explained in Memory and Constants, some other directives exist to aid concision and readability, and can be expanded by the assembler, similar to Preprocessors.
Load Literal Values
LDR R0, =x where x is an integer:
- If
xcan be represented as a literal, then the line will be replaced withMOV R0, #x - Otherwise,
xwill be defined in memory withDEFWand loaded withLDR.
Negative literals
Negative numbers cannot be used as literals. However, an attempt to do so will be recognised by the assembler and handled appropriately to produce an equivalent result, where possible. For example
ADD R0, R1, #-1assembles toSUB R0, R1, #1CMP R0, #-1assembles toCMN R0 #1(CMN= “compare negative”)MOV R3, #-3assembles toMVN R3, #2(MVN= “move not“, not “move negative”)
Loading Addresses into Memory
The ADR instruction can be used a load an address into memory:
ADR R1, ad
ad DEFW 1111The assembler may be able to convert this to a single instruction, for example ADD R1, PC #offset
In order to load any 32-bit address, ADRL can be used:
ADRL R1, ad
ad DEFW 1111It is used in the same way as ADR but will be able to load any 32-bit address. When assembled, it will require up to 4 instructions.
Other Directives Relating to Memory
ALIGN- leave an appropriate number of bytes blank to ensure that the next item starts on a word boundary. (useful after instructions such asDEFB)ORIGIN [addr]- put the following code or data in memory from addressaddrENTRY- define the entry point of the program by setting the initial value of the program counter to this address of this instruction.