Hardware Reference
In-Depth Information
; the following eight instructions subtract the divisor from register R
ldd R 1 2,sp
subd divisor 1 2,sp
std buf 1 2,sp
ldaa R 1 1,sp
sbca divisor 1 1,sp
staa buf 1 1,sp
ldaa R,sp
sbca divisor,sp
bcs smaller
; the following six instructions store the difference back to R register
staa
R,sp
ldaa
buf 1 1,sp
staa
R 1 1,sp
ldd
buf 1 2,sp
std
R 1 2,sp
bset
Q 1 3,sp,$01
; set the least significant bit of Q register to 1
bra
looptest
smaller
bclr
Q 1 3,sp,$01
; set the least significant bit of Q register to 0
looptest dec i,sp
lbne loop
; the following four instructions copy the remainder into the hole in the stack
ldd R,sp
std rem,sp
ldd R 1 2,sp
std rem 1 2,sp
; the following four instructions copy the quotient into the hole in the stack
ldd
Q,sp
std
quo,sp
ldd
Q 1 2,sp
std
quo 1 2,sp
leas
locVar,sp
; deallocate local variables
puly
pulx
puld
rts
;
org
$FFFE
; uncomment this line for CodeWarrior
;
dc.w
start
; uncomment this line for CodeWarrior
end
4.7.2 Finding the Square Root
There are several methods available for finding the square root of a number q . One of the
methods is based on successive approximation shown in Figure 4.12. The square root of a 2 n -
bit number is n bits long. The successive approximation method computes the square root of a
32-bit integer in the following manner:
Step 1
sar
0; mask
$8000; lpcnt
16; temp
0
 
Search WWH ::




Custom Search