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 x can be represented as a literal, then the line will be replaced with MOV R0, #x
  • Otherwise, x will be defined in memory with DEFW and loaded with LDR.

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, #-1 assembles to SUB R0, R1, #1
  • CMP R0, #-1 assembles to CMN R0 #1 (CMN = “compare negative”)
  • MOV R3, #-3 assembles to MVN 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 1111

The 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 1111

It 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 as DEFB)
  • ORIGIN [addr] - put the following code or data in memory from address addr
  • ENTRY - define the entry point of the program by setting the initial value of the program counter to this address of this instruction.