Hardware Reference
In-Depth Information
ldd
#dvdendLO
pshd
ldd
#dvdendHI
pshd
ldd
#dvsorLO
pshd
ldd
#dvsorHI
pshd
jsr div32 ; call the divide subroutine
; the following instruction deallocates the stack space used by the divisor and dividend
leas 8,SP
; the following four instructions get the quotient from the stack
puld
std
quotient
puld
std quotient
1
2
; the following four instructions get the remainder from the stack
puld
std
remain
puld
std
remain
1
2
;
bra
$
; uncomment this instruction for CodeWarrior
swi
;
*********************************************************************************
; The following subroutine divides an unsigned 32-bit integer by another unsigned
; 32-bit integer
; *********************************************************************************
div32
pshd
pshx
pshy
leas
2
locVar,sp
; allocate space for local variables
ldd
#0
std
R,sp
; initialize register R to 0
std
R
1
2,sp
; ''
ldd
dividend,sp
; place dividend in register Q
std
Q,sp
; ''
ldd
dividend
1
2,sp ; ''
std
Q+2,sp
; ''
ldaa
#32
; initialize loop count
staa
i,sp
; ''
loop
lsl
Q
1
3,sp
; shift register pair Q and R to the left
rol
Q
1
2,sp
; by 1 bit
rol
Q
1
1,sp
; ''
rol
Q,sp
; ''
rol
R
1
3,sp
; ''
rol
R
1
2,sp
; ''
rol
R
1
1,sp
; ''
rol
R,sp
; ''
Search WWH ::
Custom Search