04 - Multiplication and Division
04 - Multiplication and Division
04 - Multiplication and Division
Division
CMPE 364
Microprocessor Based Design
SPRING 2021
2
Multiplication
ARM has hardware support for different Multiply
instructions
Signed, unsigned, 32-bit, 64-bit, and Multiply-And-
Accumulate.
Multiply the contents of a pair of registers and, depending
upon the instruction, accumulate the results in another
register.
The long multiply accumulates into a pair of registers
representing a 64-bit value.
The final result is placed in a destination register or a
pair of registers.
3
Multiplication
Syntax: MUL{<cond>}{S} Rd, Rm, Rs
MLA{<cond>}{S} Rd, Rm, Rs, Rn
UMLAL unsigned multiply accumulate long [RdHi, RdLo]= [RdHi, RdLo]+ (Rm ∗Rs)
SMLAL signed multiply accumulate long [RdHi, RdLo]= [RdHi, RdLo]+ (Rm ∗Rs)
4
MUL Instruction
Syntax
MUL rd, rm, rs
EXAMPLE
MUL r0, r2, r0
r0 = 0xFFFFFFFE, r2 = 0xFFFFFFFF
SOLUTION
r0 = 00000002
6
UMULL Instruction
Syntax
UMULL rdlo, rdhi, rm, rs
7
UMULL Instruction
EXAMPLE
UMULL r5, r4, r8, r0
r8 = 0x08065310, r0 = 0x00410EEF
SOLUTION
[r4, r5] = r8 * r0
Result 0X00020A12 ED826BF0
r4 = 0x00020A12, r5 = 0xED826BF0
8
SMULL Instruction
Syntax
SMULL rdlo, rdhi, rm, rs
9
SMULL Instruction
EXAMPLE
SMULL r10, r9, r2, r4
r2 = FFFFFF4F, r4 = 000000A0
SOLUTION
[r9, r10] = r2 * r4
r2 = -177, r4 = 160
RES = -177 * 160 = -28,320
= FFFF FFFF FFFF 9160
r9 = FFFF FFFF, r10 = FFFF 9160
10
MLA Instruction
Syntax
MLA rd, rm, rs, rn
11
MLA Instruction
EXAMPLE
MLA r0, r4, r3, r6
r3 = 00000018
r4 = 0000C801
r6 = 00000005
SOLUTION
r0 = r4 * r3 + r6
r0 = 0000 C801 * 0000 0018 + 0000 0005
r0 = 0012 C01D
12
UMLAL Instruction
Syntax
UMLAL rdlo, rdhi, rm, rs
13
UMLAL Instruction
EXAMPLE
UMLAL r2, r3 r1, r8
r1= 1008 0040, r2 = 000A 6C20,
r3 = 0000 8000, r8 = 0000 0560
Solution
r1 × r8 = 0000 0056 2B01 5800
[r3, r2] = 0000 8000 000A 6C20
+ 0000 0056 2B01 5800
= 0000 8056 2B0B C420.
r2 = 2B0B C420
r3 = 0000 8056
14
SMLAL Instruction
Syntax
SMLAL rdlo, rdhi, rm, rs
SOLUTION
[r5, r4] = [r5, r4]+ r1*r6
[r5, r4] = FFFC BFA4 22B9 1160
r4 = 22B9 1160
r5 = FFFC BFA4 16
DIVISION
No Division instruction in ARM
Do it by software.
Method 1: can be carried out using successive
subtraction
Quotient is number of times the divisor is subtracted
from dividend before a negative value is reached
Method 2: model an algorithm after long division
See book Figure on page 41 [Schindler]
17