Hardware Reference
In-Depth Information
ldd
pNumHi,SP
cpd
#0
bne
testPR
; upper half nonzero, then enter normal test
ldd
pNumLo,SP
; if upper half is 0, then test lower half
cpd
#0
; is lower half equal to 0?
beq
nonPri
; 0 is not a prime
cpd
#1
; is lower half equal to 1
beq
nonPri
; 1 is not a prime
testPR
ldd
pNumLo,SP
; find the square root of Num
ldx
pNumHi,SP
; ''
pshd
; ''
pshx
; ''
jsr
findsqr
; ''
leas
4,SP
; deallocate space for passing parameters
std
tlimit,SP
; save returned value as the prime test limit
movw
#2,ii,SP
; initialize test divide number to 3
divLoop
ldd
ii,SP
cpd
tlimit,SP
; has test divided all numbers up to tlimit?
bhi
isPRI
; the number is prime
ldd
pNumLo,SP
; divide Num by ii
ldx
pNumHi,SP
; ''
ldy
ii,SP
; ''
leas
2 8,SP
; ''
pshd
; '' (push pNumLo)
pshx
; '' (push pNumHi)
pshy
; '' (push ii)
movw
#0,2, 2 SP
; '' (push 0 to the stack)
jsr
div32
; '' (call the divide subroutine)
leas
14,SP
; deallocate the space used by outgoing parameters
puld
; get the lower 2 bytes of the remainder
cpd
#0
; is remainder equal to 0?
beq
nonPRI
; If remainder equals 0, then Num is not a prime
ldd
ii,SP
; test divide the next higher integer
addd
#1
; ''
std
ii,SP
; ''
bra
divLoop
isPRI
ldaa
#1
bra
exitPT
nonPRI
ldaa
#0
exitPT
leas
pLocal,SP
puly
pulx
rts
#include “c:\miniide\findsqr.asm”
#include “c:\miniide\div32.asm”
;
org
$FFFE
; uncomment this line for CodeWarrior
;
dc.w
start
; uncomment this line for CodeWarrior
end
 
Search WWH ::




Custom Search