Memory

Reserving and Intialising Memory

  • Memory locations can be reserved and initialised with a value using DEFW (define word): total DEFW 0.
  • To define a single byte, DEFB can be used.
  • To reserve an arbitrary number of bytes n, each initialised with value fill, the DEFS instruction can be used as such: DEFS n, fill

Moving Data in Memory

Values can be transferred between memory and registers:

  • LDR R1, total - Load the value in memory referred to by total into R1.
  • STR R1, total - Store the value in R1 in the memory address given by total. Values can also be moved between registers:
  • MOV R1, R2 - Move the value in R2 to R1.

Literals

Literal values can be used in place of the second source operand in some arithmetic operations. A literal value is denoted by a hash (#).

Warning

Literal values cannot be used with all instructions, including MUL.

SUB R1, R2, #10 - Subtract 10 from the value at R2 and store the result in R1.

The restriction that a literal value can only be used as the second operand creates a need for a new arithmetic operation for reverse subtraction: RSB R1, R2, #10 - Subtract the value at R2 from 10 and store the result in R1.

Literal values can be defined as constants and replaced by the assembler using EQU:

ADD R1, R2, #one
one EQU 1

As these values are handled by the assembler, we can perform arithmetic operations with these constants at compile-time:

ADD R1, R2, #(one + two)
one EQU 1
two EQU 2