Hardware Reference
In-Depth Information
Step 2
temp
←
sar OR mask
Step 3
If ((temp ** 2) > num) sar
←
temp;
Step 4
mask
←
mask srl 1 (shift right logically one place);
Step 5
lpcnt
←
lpcnt 2 1
Step 6
If (lpcnt 55 0) stop; else go to step 2.
Start
SAR[n − 1, . . . , 0]
0
←
i
←
n −1
SAR[i]
1
←
Yes
i
←
i −1
SAR * SAR > num?
SAR[i]
←
0
No
No
i = 0?
Yes
Stop
Figure 4.12
■
Successive-approximation method for finding square root
Example 4.8
▼
Write a subroutine to implement the square root algorithm. This subroutine must be
able to find the square root of a 32-bit unsigned integer. The parameter
q
(for which we want
to find the square root) is pushed into the stack and the square root is returned in double
accumulator D.
Solution:
Four local variables are needed for implementing the square root algorithm.
•
mask
. set a bit in the SAR register to be 1
•
sar
. successive approximation register
•
temp
. the value of (
mask
OR
sar
)
•
lpcnt
. number of loop iterations to be performed
The stack frame of this algorithm is shown in Figure 4.13.
Search WWH ::
Custom Search