beautypg.com

Samsung S3C2440A User Manual

Page 119

background image

ARM INSTRUCTION SET

S3C2440A RISC MICROPROCESSOR

3-62

Multiplication by 6

ADD

Ra,Ra,Ra,LSL #1

; Multiply by 3

MOV

Ra,Ra,LSL#1

; and then by 2

Multiply by 10 and add in extra number

ADD

Ra,Ra,Ra,LSL#2

; Multiply by 5

ADD

Ra,Rc,Ra,LSL#1

; Multiply by 2 and add in next digit

General recursive method for Rb := Ra*C, C a constant:

1. If C even, say C = 2^n*D, D odd:

D=1:

MOV Rb,Ra,LSL #n

D<>1:

{Rb := Ra*D}

MOV

Rb,Rb,LSL

#n

2. If C MOD 4 = 1, say C = 2^n*D+1, D odd, n>1:

D=1:

ADD Rb,Ra,Ra,LSL #n

D<>1:

{Rb := Ra*D}

ADD

Rb,Ra,Rb,LSL

#n

3. If C MOD 4 = 3, say C = 2^n*D-1, D odd, n>1:

D=1:

RSB Rb,Ra,Ra,LSL #n

D<>1:

{Rb := Ra*D}

RSB

Rb,Ra,Rb,LSL #n

This is not quite optimal, but close. An example of its non-optimality is multiply by 45 which is done by:

RSB

Rb,Ra,Ra,LSL#2

; Multiply by 3

RSB

Rb,Ra,Rb,LSL#2

; Multiply by 4*3-1 = 11

ADD

Rb,Ra,Rb,LSL# 2

; Multiply by 4*11+1 = 45

rather than by:

ADD

Rb,Ra,Ra,LSL#3

; Multiply by 9

ADD

Rb,Rb,Rb,LSL#2

; Multiply by 5*9 = 45