CSE 2312 - Brief and Incomplete ARM-7 Assembly Instruction Reference
This page contains some simplified descriptions of ARM-7 instructions. More complicated descriptions, that include more cases and combinations of arguments can be found on the online documentation page.
Making Instructions Conditional
Unless otherwise indicated, you can make every instruction conditional by changing its name to include at the end "lt", "le", "gt", "ge", "eq", or "ne". Then, the instruction gets executed based on the the value of conditional flags. The conditional flags only get updated by specific instructions, the most common of which is the cmp
instruction. For example:
-
movle r1, r2
: If the conditional flags match "less than or equal", copy the contents of r2 to r1.
-
addne r5, r6, r7
: If the conditional flags match "not equal", add r6 and r7, and store the result on r5.
Using Integer Constants as Arguments
Several instructions, including add
, and
, eor
, orr
, and sub
, and can take as third argument an integer constant. According to the ARM-7 documentation, such a constant can be:
- An 8-bit integer, or
- A 32-bit integer that is equal to an 8-bit integer that has been shifted to the left by an EVEN number of bits (0, 2, 4, ..., 30 bits).
These are some examples of integers matching the second category, given in hexadecimal:
- 0x78000000. This number is 8-bit integer 0x78 shifted 24 bits to the left.
- 0x04a00000. This number is 8-bit integer 0x4a shifted 20 bits to the left.
- 0x00050000. This number is 8-bit integer 0x05 shifted 16 bits to the left.
- 0x00000ff0. This number is 8-bit integer 0xff shifted 4 bits to the left.
List of Selected Instructions
-
add rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 can be a register or an integer constant (see section on integer constants).
- Behavior: adds rn and arg3, and stores the result on rd.
-
and rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 can be a register or an integer constant (see section on integer constants).
- Behavior: performs bitwise AND between rn and arg3, and stores the result on rd.
-
b label
:
- Argument label refers to the name of a specific line on the assembly source file. To give a name to a line, put at the beginning of the line the name followed by the ':' character.
- Behavior: program execution jumps to the specified line.
-
bl label
:
- Argument label refers to the name of a specific line on the assembly source file. To give a name to a line, put at the beginning of the line the name followed by the ':' character.
- Behavior: the link register is set to the instruction immediately following the bl instruction on the source file, and program execution jumps to the specified label.
The bl instruction is used to call a function, and the label is typically the name of the function.
-
bx r
:
- Argument r is a register. For the purposes of this class, only lr will be used as argument for bx.
- Behavior: program execution jumps to the instruction specified by the argument register. The bx instruction is used to return from a function.
-
cmp r, arg2
:
- Argument r is a register.
- Argument arg2 can be a register or an integer constant (see section on integer constants).
- Behavior: cmp sets the conditional flags, based on the result of comparing r with arg2.
-
eor rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 can be a register or an integer constant (see section on integer constants).
- Behavior: performs bitwise XOR between rn and arg3, and stores the result on rd.
-
ldr rd, [rn]
:
ldr rd, [rn, #offset]
:
ldr rd, [rn, rm]
:
- This is the instruction version of ldr:
- Argument rd is a register.
- Argument rn is a register.
- Argument offset, if present, is an integer constant (see section on integer constants).
- Argument rm, if present, is a register.
- Behavior: stores to rd the 32-bit word stored starting at the memory address specified by:
- The contents of register rn (if there is no offset or rm).
- Adding offset to the contents of rn (if an offset is specified).
- Adding rn and rm, if rm is specified.
-
ldr rd, =constant
:
- This is the pseudo-instruction version of ldr:
- Argument rd is a register.
- The second argument should be a 32-bit constant.
- Behavior: sets the contents of rd equal to the 32-bit constant.
-
ldrb rd, [rn]
:
ldrb rd, [rn, #offset]
:
ldrb rd, [rn, rm]
:
- Argument rd is a register.
- Argument rn is a register.
- Argument offset, if present, is an integer constant (see section on integer constants).
- Argument rm, if present, is a register.
- Behavior: stores to rd the single byte stored starting at the memory address specified by:
- The contents of register rn (if there is no offset or rm).
- Adding offset to the contents of rn (if an offset is specified).
- Adding rn and rm, if rm is specified.
-
lsl rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 is an integer between 0 and 31.
- Behavior: shifts the bits of rn to the left, by as many bits as specified by arg3, and stores the result on rd.
-
lsr rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 is an integer between 0 and 31.
- Behavior: shifts the bits of rn to the right, by as many bits as specified by arg3, and stores the result on rd.
-
mov r, arg2
:
- Argument r is a register.
- Argument arg2 can be a register or an integer constant (see section on integer constants).
- Behavior: mov stores on register r the content of arg2, if arg2 is a register, and the constant arg2 if arg2 is an integer.
-
mul rd, rn, rc
:
- Argument rd is a register.
- Argument rn is a register, different than rd.
- Argument rc is a register.
- Behavior: multiplies rd and rc, stores the result on rd.
-
orr rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 can be a register or an integer constant (see section on integer constants).
- Behavior: performs bitwise OR between rn and arg3, and stores the result on rd.
-
pop {register list}
:
- Argument register list is a list of registers, in ascending order. Note that, for the purpose of figuring out if the order is correct, sp is treated as r13, and lr is treated as r14.
- Behavior: reads values from the stack and stores those values to the registers in the list, and then increments the stack by the appropriate amount.
-
push {register list}
:
- Argument register list is a list of registers, in ascending order. Note that, for the purpose of figuring out if the order is correct, sp is treated as r13, and lr is treated as r14.
- Behavior: decrements the stack pointer by the required amount, and stores on the stack the values of the registers in the list.
-
str rd, [rn]
:
str rd, [rn, #offset]
:
str rd, [rn, rm]
:
- Argument rd is a register.
- Argument rn is a register.
- Argument offset, if present, is an integer constant (see section on integer constants).
- Argument rm, if present, is a register.
- Behavior: stores the contents of rd to the four bytes of memory starting at the memory address specified by:
- The contents of register rn (if there is no offset or rm).
- Adding offset to the contents of rn (if an offset is specified).
- Adding rn and rm, if rm is specified.
-
strb rd, [rn]
:
strb rd, [rn, #offset]
:
strb rd, [rn, rm]
:
- Argument rd is a register.
- Argument rn is a register.
- Argument offset, if present, is an integer constant (see section on integer constants).
- Argument rm, if present, is a register.
- Behavior: stores the contents of least significant byte of rd to the single byte of memory at the memory address specified by:
- The contents of register rn (if there is no offset or rm).
- Adding offset to the contents of rn (if an offset is specified).
- Adding rn and rm, if rm is specified.
-
sub rd, rn, arg3
:
- Argument rd is a register.
- Argument rn is a register.
- Argument arg3 can be a register or an integer constant (see section on integer constants).
- Behavior: subtracts arg3 from rn, and stores the result on rd.
Back to the resources page.
Back to the CSE 2312 home page.