Hardware Reference
In-Depth Information
Solution: The logic structure of the program is as follows:
Step 1
Output the message “The prime numbers between 1000 and 2000 are as follows:”.
Step 2
For every number between 1000 and 2000, do the following:
1. Call the PrimeTest() subroutine to see if it is a prime.
2. Output the number (call printf() ) if it is a prime.
3. If there are already eight prime numbers in the current line, then also output a carry
return.
The assembly program is as follows:
CR
equ
$0D
LF
equ
$0A
upper
equ
2000
; upper limit for testing prime
lower
equ
1000
; lower limit for testing prime
printf
equ
$EE88
; location where the address of printf() is stored
org
$1000
out_buf ds.b
10
PRIcnt
ds.b
1
; prime number count
k
ds.b
2
tmp
ds.b
2
org
$1500
start
ldx
#upper
stx
tmp
pshx
ldx
#lower
stx
k
; initialize k to 1000 for prime testing
pshx
ldd
#form0
jsr
[printf,PCR]
leas
4,sp
clr
PRIcnt
again
ldd
k
cpd
#upper
bhi
Pstop
; stop when k is greater than upper
pshd
ldd
#0
pshd
jsr
primetest
; test if k is prime
leas
4,sp
; deallocate space used by outgoing parameters
tsta
beq
next_k
; test next integer if k is not prime
inc
PRIcnt
; increment the prime count
ldd
k
pshd
ldd
#form1
jsr
[printf,PCR] ; output k
leas
2,sp
Search WWH ::




Custom Search