ARM VERSION 1.2 manual Ratio DivMod r0,r5,r4,r2

Models: VERSION 1.2

1 360
Download 360 pages 38.37 Kb
Page 62
Image 62

Writing ARM and Thumb Assembly Language

The macro checks that no two parameters use the same register. It also optimizes the code produced if only the remainder is required.

To avoid multiple definitions of labels if DivMod is used more than once in the assembler source, the macro uses local labels (90, 91). Refer to Local labels on page 2-13 for more information.

Example 2-15 shows the code that this macro produces if it is invoked as follows:

ratio DivMod r0,r5,r4,r2

 

 

 

 

Example 2-15

 

 

 

 

 

 

ASSERT

r5

<> r4

; Produce an error if the

 

ASSERT

r5

<> r2

; registers supplied are

 

ASSERT

r4

<> r2

; not all different

 

ASSERT

r0

<> r5

; These three only matter if $Div

 

ASSERT

r0

<> r4

; is not null ("")

 

ASSERT

r0

<> r2

;

ratio

 

 

 

 

 

MOV

r2, r4

; Put divisor in $Temp

 

CMP

r2, r5, LSR #1

; double it until

90

MOVLS

r2, r2, LSL #1

; 2 * r2 > r5

 

CMP

r2, r5, LSR #1

 

 

BLS

%b90

; The b means search backwards

 

MOV

r0, #0

; Initialize quotient

91

CMP

r5, r2

; Can we subtract r2?

 

SUBCS

r5, r5, r2

; If we can, do so

 

ADC

r0, r0, r0

; Double r0

 

MOV

r2, r2, LSR #1

; Halve r2,

 

CMP

r2, r4

; and loop until

 

BHS

%b91

; less than divisor

 

 

 

 

 

2-50

Copyright © 2000, 2001 ARM Limited. All rights reserved.

ARM DUI 0068B

Page 62
Image 62
ARM VERSION 1.2 manual Ratio DivMod r0,r5,r4,r2