Writing ARM and Thumb Assembly Language
ARM DUI 0068B
Copyright © 2000, 2001 ARM Limited. All rights reserved.
2-49
2.9.2
Unsigned integer division macro example
Example 2-14 shows a macro that performs an unsigned integer division. It takes four
parameters:
$Bot
The register that holds the divisor.
$Top
The register that holds the dividend before the instructions are executed.
After the instructions are executed, it holds the remainder.
$Div
The register where the quotient of the division is placed. It can be
NULL
(
""
) if only the remainder is required.
$Temp
A temporary register used during the calculation.
Example 2-14
MACRO
$Lab DivMod $Div,$Top,$Bot,$Temp
ASSERT $Top <> $Bot ; Produce an error message if the
ASSERT $Top <> $Temp ; registers supplied are
ASSERT $Bot <> $Temp ; not all different
IF "$Div" <> ""
ASSERT $Div <> $Top ; These three only matter if $Div
ASSERT $Div <> $Bot ; is not null ("")
ASSERT $Div <> $Temp ;
ENDIF
$Lab
MOV $Temp, $Bot ; Put divisor in $Temp
CMP $Temp, $Top, LSR #1 ; double it until
90 MOVLS $Temp, $Temp, LSL #1 ; 2 * $Temp > $Top
CMP $Temp, $Top, LSR #1
BLS %b90 ; The b means search backwards
IF "$Div" <> "" ; Omit next instruction if $Div is null
MOV $Div, #0 ; Initialize quotient
ENDIF
91 CMP $Top, $Temp ; Can we subtract $Temp?
SUBCS $Top, $Top,$Temp ; If we can, do so
IF "$Div" <> "" ; Omit next instruction if $Div is null
ADC $Div, $Div, $Div ; Double $Div
ENDIF
MOV $Temp, $Temp, LSR #1 ; Halve $Temp,
CMP $Temp, $Bot ; and loop until
BHS %b91 ; less than divisor
MEND
Содержание Developer Suite
Страница 10: ...Preface x Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 110: ...Assembler Reference 3 32 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 185: ...ARM Instruction Reference ARM DUI 0068B Copyright 2000 2001 ARM Limited All rights reserved 4 75 Example MSR CPSR_f r5 ...
Страница 238: ...Thumb Instruction Reference 5 44 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 282: ...Vector Floating point Programming 6 44 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...
Страница 360: ...Index Index 6 Copyright 2000 2001 ARM Limited All rights reserved ARM DUI 0068B ...