This comprehensive ARM Assembly cheat sheet provides a fundamental overview of ARM assembly programming, including registers, update modes, and memory addressing, as well as a detailed list of essential ARM instructions such as arithmetic, branching, bitwise logic, comparison, data movement, and memory access operations. It serves as a quick reference for beginners and seasoned programmers alike, offering insights into the basics of ARM architecture and instruction set to facilitate data manipulation, function management, and efficient memory handling.
The Basics
Registers (reg
)
In ARM assembly language, registers are denoted by reg
and can refer to any of the general-purpose registers or specific system registers. Here is the explanation of the register naming conventions:
R0
toR15
: General-purpose registers, where the number indicates the specific register. These are used for a wide range of purposes, from holding data and addresses to intermediate calculations.SP
(Stack Pointer): This is registerR13
. It is used to point to the last item in the stack, a critical function in managing function calls and local variables.LR
(Link Register): RegisterR14
serves as the link register. It typically holds the return address when a subroutine is called, allowing the program to return to the correct location after the subroutine is completed.PC
(Program Counter): RegisterR15
acts as the program counter. It holds the address of the next instruction to be executed. Changing the value ofPC
can thus alter the flow of execution in the program.
These registers are integral to ARM assembly programming, facilitating data manipulation, function call management, and control flow.
Update Mode (um
)
The update mode (um
) specifies how the base register is updated during multiple register load/store instructions. The following are the update modes available in ARM assembly:
FA
/IA
: Full Ascending / Increment After - The base register is updated to point to the next address after the current block of data. This mode starts accessing memory at the current base register address and increments the address after each access.EA
/IB
: Empty Ascending / Increment Before - The base register is updated to point to the next address before accessing the current block of data. This mode increments the base address before accessing memory, starting with the new address.FD
/DB
: Full Descending / Decrement Before - The base register is updated to point to the previous address before accessing the current block of data. This mode starts by decrementing the base address and then accessing memory starting from this new address.ED
/DA
: Empty Descending / Decrement After - The base register is updated to point to the previous address after accessing the current block of data. This mode accesses memory starting at the current base register address and decrements the address after each access.
These modes determine how the base register's value is adjusted in relation to the data block being loaded or stored, allowing for efficient memory access patterns, especially in looping constructs or when managing arrays and buffers.
Memory Address (mem
)
Memory addressing modes specify the address used for load and store operations. The following are the formats used to specify memory addresses in ARM assembly instructions:
[reg #±imm 12]
: Direct offset - The address is the base register (reg
) offset by a constant (±imm 12
), whereimm
is a 12-bit immediate value.[reg±reg]
: Register offset - The address is the base register (reg
) offset by another register value.[rega±regbshift]
: Scaled register offset - The address is the base register (rega
) offset by a scaled (shifted) register value (regb
), whereshift
specifies the type and amount of shift applied toregb
.[reg #±imm 12]!
: Pre-indexed addressing - The base register is updated with the offset address before the memory access.[reg±reg]!
: Pre-indexed register offset - Similar to direct pre-indexed, but the offset is another register.[reg±reg shift ]!
: Pre-indexed scaled register offset - The base register is updated with the scaled (shifted) register offset before the memory access.[reg]#±imm 12
: Post-indexed addressing - The memory access occurs using the base register, which is then updated with the offset.[reg]±reg
: Post-indexed register offset - The memory access uses the base register, which is then updated with another register value.[reg]±regshift
: Post-indexed scaled register offset - The memory access uses the base register, which is then updated with a scaled (shifted) register offset.
ARM Instructions
Arithmetic
ADDcdS reg reg arg
- addSUBcdS reg reg arg
- subtractRSBcdS reg reg arg
- subtract reversed operandsADCcdS reg reg arg
- add both operands and carry flagSBCcdS reg reg arg
- subtract both operands and adds carry flag − 1RSCcdS reg reg arg
- reverse subtract both operands and adds carry flag − 1MULcdS regd regm regs
- multiply regm and regs places lower 32 bits into regdMLAcdS regd regm regs regn
- places lower 32 bits of regm · regs + regn into regdUMULLcdS reglo reghi regm regs
- multiply regm and regs place 64-bit unsigned result into {reghi reglo}UMLALcdS reglo reghi regm regs
- place unsigned regm · regs + {reghi reglo} into {reghi reglo}SMULLcdS reglo reghi regm regs
- multiply regm and regs place 64-bit signed result into {reghi reglo}SMLALcdS reglo reghi regm regs
- place signed regm · regs + {reghi reglo} into {reghi reglo}
Branching
Bcd imm24
- branch to imm 24 words awayBLcd imm24
- copy PC to LR then branchBXcd reg
- copy reg to PC and exchange instruction sets (T flag := reg[0])SWIcd imm24
- software interrupt
Bitwise Logic
ANDcdS reg reg arg
- bitwise ANDORRcdS reg reg arg
- bitwise OREORcdS reg reg arg
- bitwise exclusive-ORBICcdS reg rega argb
- bitwise rega AND (NOT arg b)
Comparison
CMPcd reg arg
- update flags based on subtractionCMNcd reg arg
- update flags based on additionTSTcd reg arg
- update flags based on bitwise ANDTEQcd reg arg
- update flags based on bitwise exclusive-OR
Data Movement
MOVcdS reg arg
- copy argumentMVNcdS reg arg
- copy bitwise NOT of argument
Memory Access
LDRcdB reg mem
- loads word/ byte/ half from memory into a registerSTRcdB reg mem
- stores word/ byte/ half to memory from a registerLDMcd um reg! mreg
- loads into multiple registersSTMcd um reg! mreg
- stores multiple registersSWPcdB regd regm [regn]
- copies regm to memory at regn, old value at address regn to regd
Shift
LSL #imm 5
: shift left 0 to 31LSR #imm 5
: logical shift right 1 to 32ASR #imm 5
: arithmetic shift right 1 to 32ROR #imm 5
: rotate right 1 to 31RRX
: rotate carry bit into top bitLSL reg
: shift left by registerLSR reg
: logical shift right by registerASR reg
: arithmetic shift right by registerROR reg
: rotate right by register
Notes:
S
= set condition flagsB
= byte, can be replaced by H for half word(2 bytes)cd
: condition code (e.g.,AL
or omitted for always,EQ
for equal,NE
for not equal, etc.)reg
: register (e.g.,R0 to R15
,SP
for stack pointer,LR
for link register,PC
for program counter)arg
: right-hand argument (e.g.,#imm 8
for immediate on 8 bits possibly rotated right,reg
for register, etc.)shift
: shift register value (e.g.,LSL #imm 5
for shift left 0 to 31,LSR #imm 5
for logical shift right 1 to 32, etc.)mem
: memory address (e.g.,[reg #±imm 12]
for register offset by constant,[reg±reg]
for register offset by variable bytes, etc.)