Module-5 Theory
Module-5 Theory
Authors:
Andrew N. Sloss Dominic Symes Chris Wright
Don’t write or place any
Publication: image in this area
There are few data processing instructions that do not use the
barrel shift, for example, the MUL (multiply), CLZ (count leading zeros),
and QADD (signed saturated 32-bit add) instructions.
Data movement
These instructions copy the data N into the register.
The various instructions are
MOV, MVN
Syntax: <Operation> {<cond>} {S} Rd, N
MOV Move a 32-bit value into a register Rd = N Don’t write or place any
MVN move the NOT of the 32-bit value Rd = ∼N image in this area
into a register
Dr. D Khalandar Basha
Rd<= ~N
Dr. D Khalandar Basha
Arithmetic Instructions
The arithmetic instructions implement addition and subtraction of 32-bit signed
and unsigned values.
The various instructions are
ADD, ADC, RSB, RSC, SUB, SBC
Syntax: <instruction> {<cond>} {S} Rd, Rn, N Don’t write or place any
image in this area
Dr. D Khalandar Basha
Arithmetic Instructions
Example
SUB r0, r1, r2
PRE POST
r0 = 0x00000000 r0 = 0x00000001
r1 = 0x00000002
r2 = 0x00000001
Don’t write or place any
image in this area
Dr. D Khalandar Basha
Arithmetic Instructions
Example
SUBS r1, r1, #1;
PRE POST
Arithmetic Instructions
Example
RSB r0, r1, #0 ; Rd = 0x0 - r1
PRE POST
Arithmetic Instructions
Example
RSB r0, r1, #0 ; Rd = 0x0 - r1
PRE POST
The wide range of second operand shifts available on arithmetic and logical
instructions is a very powerful feature of the ARM instruction set.
ADD r0, r1, r1, LSL #1
PRE POST
r0 = 0x00000000 r0 = 0x0000000f
r1 = 0x00000005 r1 = 0x00000005
Don’t write or place any
Register r1 is first shifted one location to the left to give the value of twice r1. image in this area
The ADD instruction then adds the result of the barrel shift operation to
register r1.
The final result in register r0 is equal to three times the value in register r1.
Dr. D Khalandar Basha
Logical Instructions
Logical instructions perform bitwise logical operations on the two source registers.
The various instructions are
AND, ORR, EOR, BIC
the flags
Rd<= Rn & N
Dr. D Khalandar Basha
BIC- logical clear (AND NOT). This instruction is particularly useful when clearing
status bits and is frequently used to change interrupt masks in the cpsr.
Syntax: BIC Rd, Rn, N
This instruction logic bit clear bit by bit between the value stored in register Rn
with N. The result is stored in register Rd.
Rd<= Rn & ~N
Syntax: BICS Rd, Rn, N Don’t write or place any
image in this area
This instruction logic bit clear bit by bit between the value stored
In Rn with N. The result is stored in Rd and the CPSR is updated
Dr. D Khalandar Basha
Logical Instructions
Example
ORR r0, r1, r2
PRE POST
r0 = 0x00000000 r0 = 0x12345678
r1 = 0x02040608
r2 = 0x10305070
Don’t write or place any
image in this area
Dr. D Khalandar Basha
Logical Instructions
Example
BIC r0, r1, r2
PRE POST
r1 = 0b1111 0b1010
r2 = 0b0101
Comparison Instructions
The comparison instructions are used to compare or test a register with a 32-bit
value.
They update the CPSR flag bits according to the result, but do not affect other
registers.
The various instructions are
CMP, CMN, TEA, TST Don’t write or place any
image in this area
Syntax: <instruction> {<cond>} Rn, N
Dr. D Khalandar Basha
The CMP is effectively a subtract instruction with the result discarded. The result
affects the flags in CPSR.
Flags <= Rn – N
Don’t write or place any
image in this area
Dr. D Khalandar Basha
The CMN is effectively a add instruction with the result discarded. The result
affects the flags in CPSR.
Flags <= Rn + N
Don’t write or place any
image in this area
Dr. D Khalandar Basha
The TEQ is a logical exclusive OR operation. For each, the results are discarded
but the condition bits are updated in the CPSR.
Flags <= Rn ^ N
Don’t write or place any
image in this area
Dr. D Khalandar Basha
The TST is a logical AND operation. For each, the results are discarded but the
condition bits are updated in the CPSR.
Flags <= Rn & N
Don’t write or place any
image in this area
Dr. D Khalandar Basha
Logical Instructions
Example
CMP r0, r9
PRE POST
Multiply Instructions
The multiply instructions multiply the contents of a pair of registers and, depending
upon the instruction, accumulate the results in with another register.
The long multiplies accumulate onto a pair of registers representing
a 64-bit value. The final result is placed in a destination register or
a pair of registers.
The various instructions are Don’t write or place any
image in this area
MUL, MLA
SMULL, UMULL, SMLAL, UMLAL
Dr. D Khalandar Basha
The MUL instruction, multiply the contents of Rm and Rs registers and the results
store in Rd register.
Rd <= Rm * Rs Don’t write or place any
image in this area
is placed in two registers RdLo and RdHi. RdLo holds the lower
32 bits, and RdHi holds the higher 32 bits of the 64-bit result.
Dr. D Khalandar Basha
SMULL – signed multiply long two 32-bit values, the result is 64 bits.
Syntax: SMULL {<cond>} {S} RdLo, RdHi, Rm, Rs
UMULL – Unsigned multiply long two 32-bit values, the result is 64 bits.
Syntax: UMULL {<cond>} {S} RdLo, RdHi, Rm, Rs
SMLAL – Unsigned multiply accumulate long two 32-bit values, the result is 64 bits.
Syntax: SMLAL {<cond>} {S} RdLo, RdHi, Rm, Rs
The SMLAL instruction, is signed multiplication of Rm and Rs registers and
accumulate the product to [RdHi, RdLo] contents and
register RdLo contains the lower 32 bits, and
register RdHi contains the higher 32 bits of the 64-bit result.
. [RdHi, RdLo] <= [RdHi, RdLo] + Rm * Rs Don’t write or place any
image in this area
UMLAL – Unsigned multiply accumulate long two 32-bit values, the result is 64 bits.
Syntax: UMLAL {<cond>} {S} RdLo, RdHi, Rm, Rs