Skip to content

ARM Data Processing Instructions ​

ARM Registers ​

ARM has 16 programmer-visible registers and a Current Program Status Register 0xCPSR, R0 to R15. These registers are used to store data and addresses. The first 13 registers are general-purpose registers, and the last three registers are used for special purposes.

Special Purpose Registers ​

  • R13 (SP): Stack Pointer
  • R14 (LR): Link Register
  • R15 (PC): Program Counter

Current Program Status Register (CPSR) ​

  • N: Negative, set if the result is negative.
  • Z: Zero, set if the result is zero.
  • C: Carry, set if there is a carry out of the most significant bit.
  • V: Overflow, set if the result causes an overflow.

ARM Instructions ​

ARM Instructions is encoded in 32-bit words. The instructions are divided into three categories:

  1. Data Processing Instructions: These instructions perform arithmetic operations on data.
  2. Load and Store Instructions: These instructions are used to load and store data from memory.
  3. Control Flow Instructions: These instructions are used to control the flow of the program.

And they have the general format as follows:

asm
{LABEL}  OPCODE{CONDITION}  OPERANDS ; Comment

The CONDITION flag is optional and allows the instructions to be excuted only if a specified condition is met. Some of the common conditions are:

Condition CodeMnemonicExplanation
EQEqualExecutes if the Zero (Z) flag is set (result is zero).
NENot EqualExecutes if the Zero (Z) flag is clear (result is nonzero).
CS / HSCarry Set / Unsigned Higher or SameExecutes if the Carry (C) flag is set (unsigned comparison: >=).
CC / LOCarry Clear / Unsigned LowerExecutes if the Carry (C) flag is clear (unsigned comparison: <).
MINegativeExecutes if the Negative (N) flag is set (result is negative).
PLPositive or ZeroExecutes if the Negative (N) flag is clear (result is positive or zero).
VSOverflow SetExecutes if the Overflow (V) flag is set (arithmetic overflow occurred).
VCOverflow ClearExecutes if the Overflow (V) flag is clear (no overflow).
HIUnsigned HigherExecutes if both the Carry (C) flag is set and the Zero (Z) flag is clear (unsigned comparison: >).
LSUnsigned Lower or SameExecutes if the Carry (C) flag is clear or the Zero (Z) flag is set (unsigned comparison: <=).
GEGreater or EqualExecutes if the Negative (N) flag equals the Overflow (V) flag (signed comparison: >=).
LTLess ThanExecutes if the Negative (N) flag is not equal to the Overflow (V) flag (signed comparison: <).
GTGreater ThanExecutes if the Zero (Z) flag is clear and the Negative (N) flag equals the Overflow (V) flag (signed comparison: >).
LELess Than or EqualExecutes if the Zero (Z) flag is set or the Negative (N) flag is not equal to the Overflow (V) flag (signed comparison: <=).
ALAlwaysDefault condition; executes unconditionally.

Data Processing Instructions ​

Data processing instructions perform arithmetic, logical, and shift operations on registers.

Arithmetic Instructions ​

These instructions perform basic mathematical operations like addition, subtraction, and multiplication.

InstructionMnemonicAssembler SyntaxDescription
ADDAddADD Rd, Rn, RmAdds two registers.
SUBSubtractSUB Rd, Rn, RmSubtracts one register from another.
RSBReverse SubtractRSB Rd, Rn, RmSubtracts with reversed operands.
ADCAdd with CarryADC Rd, Rn, RmAdds two registers with carry.
SBCSubtract with CarrySBC Rd, Rn, RmSubtracts with carry.
RSCReverse Subtract with CarryRSC Rd, Rn, RmReverse subtraction with carry.
MULMultiplyMUL Rd, Rn, RmMultiplies two registers.
MLAMultiply AccumulateMLA Rd, Rn, Rm, RaMultiplies and adds an accumulator.
UMULLUnsigned Multiply LongUMULL RdLo, RdHi, Rn, RmStores 64-bit result across RdLo and RdHi.
SMULLSigned Multiply LongSMULL RdLo, RdHi, Rn, RmSame as UMULL but for signed numbers.
SDIVSigned DivideSDIV Rd, Rn, RmDivides two signed numbers.
UDIVUnsigned DivideUDIV Rd, Rn, RmDivides two unsigned numbers.

Logical Instructions ​

These instructions perform bitwise operations like AND, OR, and XOR.

InstructionMnemonicAssembler SyntaxDescription
ANDBitwise ANDAND Rd, Rn, RmPerforms bitwise AND.
ORRBitwise ORORR Rd, Rn, RmPerforms bitwise OR.
EORBitwise XOREOR Rd, Rn, RmPerforms bitwise XOR.
BICBitwise ClearBIC Rd, Rn, RmClears specific bits.
MVNBitwise NOTMVN Rd, RmInverts all bits.

Shift Instructions ​

Shift instructions move bits left or right within a register.

InstructionMnemonicAssembler SyntaxDescription
LSLLogical Shift LeftLSL Rd, Rm, #nShifts left, filling with zeros.
LSRLogical Shift RightLSR Rd, Rm, #nShifts right, filling with zeros.
ASRArithmetic Shift RightASR Rd, Rm, #nPreserves the sign bit.
RORRotate RightROR Rd, Rm, #nRotates right by n bits.
RRXRotate Right with ExtendRRX Rd, RmRotates right with carry flag.

Move Instructions ​

Move instructions copy data between registers.

InstructionMnemonicAssembler SyntaxDescription
MOVMoveMOV Rd, RmMoves a value from one register to another.
MOVMove immediateMOV Rd, #immMoves an immediate value to Rd
MVNMove NegativeMVN Rd, RmMoves the bitwise NOT of a register.
MOVTMove TopMOVT Rd, #imm16Moves the top 16 bits of a 32-bit value.

Load and Store Instructions ​

Load and store instructions transfer data between registers and memory.

InstructionMnemonicAssembler SyntaxDescription
LDRLoad RegisterLDR Rd, [Rn]Loads a value from memory into a register.
STRStore RegisterSTR Rd, [Rn]Stores a register value into memory.

Control Flow Instructions ​

Control flow instructions change the execution sequence of a program.

InstructionMnemonicAssembler SyntaxDescription
BBranchB labelJumps to a target address unconditionally.
BLBranch with LinkBL labelCalls a subroutine (stores return address in LR).
BXBranch and ExchangeBX RmBranches to an address and switches ARM/Thumb mode.
CMPCompareCMP Rn, RmCompares two registers (Rn - Rm, updates flags only).
CMNCompare NegativeCMN Rn, RmCompares two registers (Rn + Rm, updates flags only).
TSTTest BitsTST Rn, RmPerforms Rn & Rm, updates flags only.
TEQTest EquivalenceTEQ Rn, RmPerforms Rn ^ Rm, updates flags only.

For more instructions and their details, refer to the ARM Instruction Set Summary.


Examples ​

Example 1 ​

asm
    PRESERVE8
    THUMB
    AREA  RESET, DATA, READONLY
    EXPORT __Vectors
__Vectors
    DCD 0x20001000
    DCD Reset_Handler
    ALIGN
    AREA MYCODE, CODE, READONLY
    ENTRY
    EXPORT Reset_Handler
Reset_Handler
    MOV R0, #7 ; x = 7
    MUL R1, R0, R0 ; R1 = x^2
    MOV R4, #5
    MUL R1, R1, R4
    MOV R5, #6
    MUL R2, R0, R5 ; R2 = 6x
    SUB R3, R1, R2 ; R3 = 5x^2 - 6x
    ADD R3, R3, #8 ; R3 = 5x^2 - 6x + 8
    ALIGN
STOP
    B STOP
    END

Example 2 ​

asm
    PRESERVE8
    THUMB
    AREA  RESET, DATA, READONLY
    EXPORT __Vectors
__Vectors
    DCD 0x20001000
    DCD Reset_Handler
    ALIGN
SUMP DCD SUM
NUM1 DCD 5
NUM2 DCD 7
    AREA MYDATA, DATA, READWRITE
SUM DCD 0
    AREA MYCODE, CODE, READONLY
    ENTRY
    EXPORT Reset_Handler
Reset_Handler
    LDR R1, NUM1
    LDR R2, NUM2
    MOV R0, #0
    ADD R0, R1, R2
    SUBS R0, R0, #1
    LSLS R3, R0, #2 ; Logical shift left by 2 bits with flag update
    LDR R4, SUMP
    STR R3, [R4]
    LDR R6, [R4]
    ALIGN
STOP
    B STOP
    END

Lab Work ​

Write a program to conver temperatures from Celisius to Fahrenhiet and from Fahrenhiet to Celsius using the following formulas.

C=5×(F−32)9F=9×C5+32

Criteria ​

  1. Use R0 to store the initial Celsius temperature, say 22.
  2. Use R1 to store the initial Fahrenhiet, say 70.
  3. Use R2 to store the converted temperature in Fahrenhiet.
  4. Use R3 to store the converted temperature in Celsius.