SC32442B RISC MICROPROCESSOR
THUMB INSTRUCTION SET
4-43
DIVISION BY A CONSTANT
Division by a constant can often be performed by a short fixed sequence of shifts, adds and subtracts.
Here is an example of a divide by 10 routine based on the algorithm in the ARM Cookbook in both Thumb and
ARM code.
Thumb Code
udiv10
; Take argument in a1 returns quotient in a1,
;
remainder
in
a2
MOV
a2, a1
LSR
a3, a1, #2
SUB
a1, a3
LSR
a3, a1, #4
ADD
a1, a3
LSR
a3, a1, #8
ADD
a1, a3
LSR
a3, a1, #16
ADD
a1, a3
LSR
a1, #3
ASL
a3, a1, #2
ADD
a3, a1
ASL
a3, #1
SUB
a2, a3
CMP
a2, #10
BLT
%FT0
ADD
a1, #1
SUB
a2, #10
0
MOV
pc, lr
ARM Code
udiv10
; Take argument in a1 returns quotient in a1,
;
remainder
in
a2
SUB
a2, a1, #10
SUB
a1, a1, a1, lsr #2
ADD
a1, a1, a1, lsr #4
ADD
a1, a1, a1, lsr #8
ADD
a1, a1, a1, lsr #16
MOV
a1, a1, lsr #3
ADD
a3, a1, a1, asl #2
SUBS
a2, a2, a3, asl #1
ADDPL
a1, a1, #1
ADDMI
a2, a2, #10
MOV
pc, lr
Содержание SC32442B54
Страница 1: ...SC32442B54 USER S MANUAL Revision 1 0 ...
Страница 43: ...PRODUCT OVERVIEW SC32442B RISC MICROPROCESSOR 1 42 NOTES ...
Страница 59: ...PROGRAMMER S MODEL SC32442B RISC MICROPROCESSOR 2 16 NOTES ...
Страница 123: ...ARM INSTRUCTION SET SC32442B RISC MICROPROCESSOR 3 64 NOTES ...
Страница 167: ...THUMB INSTRUCTION SET SC32442B RISC MICROPROCESSOR 4 44 NOTES ...
Страница 187: ...MEMORY CONTROLLER SC32442B RISC MICROPROCESSOR 5 20 NOTES ...
Страница 250: ...DMA SC32442B RISC MICROPROCESSOR 8 14 NOTES ...
Страница 308: ...PWM TIMER SC32442B RISC MICROPROCESSOR 10 20 NOTES ...
Страница 330: ...UART SC32442B RISC MICROPROCESSOR 11 22 NOTES ...
Страница 417: ...SC32442B RISC MICROPROCESSOR LCD CONTROLLER 15 45 NOTES ...
Страница 427: ...ADC AND TOUCH SCREEN INTERFACE SC32442B RISC MICROPROCESSOR 16 10 NOTES ...
Страница 511: ...BUS PRIORITIES SC32442B RISC MICROPROCESSOR 24 2 NOTES ...
Страница 562: ...K5D2G13ACM D075 Revision 1 0 December 2006 7 MCP MEMORY 2Gb 256Mb x8 NAND Flash Memory A Die ...
Страница 599: ...K5D2G13ACM D075 Revision 1 0 December 2006 44 MCP MEMORY 512Mb 16Mb x32 Mobile SDRAM C Die ...