Hardware Reference
In-Depth Information
SP
SP+2
mask
sar
temp
SP+4
SP+6
lpcnt
y
x
return address
q_hi
SP+13
SP+15
q_lo
Figure 4.13 Stack frame of Example 4.8
The subroutine for fi nding the square root of a 32-bit integer and its testing program is as follows:
#include
“c:\miniide\hcs12.inc”
mask
equ
0
; stack offset of the variable mask from SP
sar
equ
2
; stack offset of the variable sar from SP
temp
equ
4
; stack offset of the variable temp from SP
lpcnt
equ
6
; stack offset of 1-byte loop count from SP
q_hi
equ
13
; stack offset of the upper and lower halves of the
q_lo
equ
15
; number Q we want to find the square root from SP
testHi
equ
$00
; upper half of the test number (q)
testLo
equ
$7BC4
; lower half of the test number (q)
locVar
equ
7
org
$1000
sqroot
ds.w
1
; square root
org
$1500
start
lds
#$1500
movw
#testLo,2, 2 SP
; push testHi into stack
movw
#testHi,2, 2 SP
; push testLo into stack
jsr
findsqr
std
sqroot
; save the returned square root
leas
4,SP
; deallocate the space used in passing parameters
;
bra
$
; uncomment this line for CodeWarrior
swi
; *********************************************************************************
; The following subroutine computes the closest integer square root for the incoming
; unsigned integer pushed in the stack (q_hi and q_lo).
; *********************************************************************************
findsqr
pshx
pshy
leas
2 locVar,SP
; allocate space for local variables
movw
#0,sar,SP
; initialize sar to 0
movw
#$8000,mask,SP ; initialize mask to $8000
 
 
Search WWH ::




Custom Search