Lecture5 ARM
Lecture5 ARM
1
39v10 The ARM Architecture TM
1 1
Multiply Instructions
Instructions:
MUL Multiply 32-bit result
2
39v10 The ARM Architecture TM
2 2
Multiply instructions
Features:
Second operand can’t be immediate
The result register must be different from the first
operand
Cycles depends on core type
If S bit is set, C flag is meaningless
•Example:
UMULL r6, r5, r3. r9 ;multiplies the values of
r3 and r9 and stores the 64 bit result
as least significant 32 bits are
stored in r5 and most significant
32 bits are stored in r6.
Op c o de Mn e mo n i c Me an i n g Ef f e c t
[2 3 :2 1 ]
000 MUL Multiply (32-bit result) Rd := (Rm * Rs) [31:0]
001 MLA Multiply-accumulate (32-bit result) Rd := (Rm * Rs + Rn) [31:0]
100 UMULL Unsigned multiply long RdHi:RdLo := Rm * Rs
101 UMLAL Unsigned multiply-accumulate long RdHi:RdLo += Rm * Rs
110 SMULL Signed multiply long RdHi:RdLo := Rm * Rs
111 SMLAL Signed multiply-accumulate long RdHi:RdLo += Rm * Rs
31 28 27 24 23 21 20 19 16 15 12 11 8 7 4 3 0
cond 0000 mul S Rd/RdHi Rn/RdLo Rs 1001 Rm
B label
…
label: …
conditional branches
MOV R0, #0
loop: …
ADD R0, R0, #1
CMP R0, #10
BNE loop
CMP R0, #5
BEQ bypass @ if (R0!=5) {
ADD R1, R1, R0 @ R1=R1+R0-R2
SUB R1, R1, R2 @ }
bypass: …
smaller and faster
CMP R0, #5
ADDNE R1, R1, R0
SUBNE R1, R1, R2
Rule of thumb: if the conditional sequence is three instructions
or less, it is better to use conditional execution than a branch.
39v10 The ARM Architecture TM
16 16
Data Transfer Instructions
Another Approach:
Only indirectly R0
R1
MSR moves contents MRS
from CPSR/SPSR to R7
selected GPR MSR R8
CPSR
SPSR
MRS moves contents
from selected GPR R14
to CPSR/SPSR R15
Only in privileged
modes
36
39v10 The ARM Architecture TM
36 36
PSR Transfer Instructions
31 28 27 24 23 16 15 8 7 6 5 4 0
N Z C V Q J U n d e f i n e d I F T mode
f s x c
where
<psr> = CPSR or SPSR
[_fields] = any combination of ‘fsxc’
Also an immediate form
MSR{<cond>} <psr_fields>,#Immediate
In User Mode, all bits can be read but only the condition flags (_f) can be
written.
28 27 24 23
SWI instruction
Forces CPU into supervisor mode
Usage: SWI #n
Maximum 224 calls
Suitable for running privileged
code and
making OS calls
38
39v10 The ARM Architecture TM
38 38
Software Interrupt (SWI)
31 28 27 24 23 0
Condition Field