ADD.B D3,D5
AND.B $1004,D1
SUB.B #$12,(A4)
ADD.W (A5)+,D4
org $1000
charin equ 247
charout equ 248
stringout equ 243
tutorexit equ 228
escape equ $1B
lea prompt,a5
lea endprompt,a6
move.w #tutorexit
trap #14
move.b #20,d3
read move.w #charin,d7
trap #14
cmp.b #escape,d0
beq exit
cmp.b #'A',d0
blt read
cmp.b #'Z',d0
bgt read
move d0,d1
and.b #$01,d1
bne read
move.w #charout,d7
trap #14
sub.b #1,d3
bne read
exit move.w #tutorexit,d7
trap #14
prompt dc.b 'Please begin typing characters',$0D,$0A
endprompt dc.b 0
end $1000
vector and
places the result in the longword labeled result.
The number of values in the vector is equated to the label
VEC_LENGTH.
org $1000
VEC_LENGTH equ 10
tutorexit equ 228
main lea vector,A1
move.l #0,d1
move.l #0,result
move.b #VEC_LENGTH,d2
sum move.w (A1)+,d1
add.l d1,result
sub.b #1,d2
bne sum
exit move.w #tutorexit,D7
trap #14
* examine the next two lines of errors
vector dc.w 45,6356,10,134,9012
dc.w 345,1753,926,213,10032
result ds.l 1
end $1000
org $100
main ldaa #5
ldab #4
ldx #10
loop jsr addit
dex
bne loop
more_code ...
addit pshb
aba
rts
addit?
Explain the program's behavior if it is executed as
written. Write a correct version of addit.
Since the subroutine pushes the contents
of ACCB onto the stack, but does not restore them, the
stack pointer will incorrectly point to the return address
of the instruction following the subroutine call. In this
case, the correct address would be $010A. Without the
pull, the processor would return to the instruction at
address $0A04, which is obviously incorrect. A corrected
version of the subroutine is given by removing the
pshb instruction. Alternatively, a pulb
could be added before the rts instruction.
addit aba
rts
do...until
addit is written
correctly, what value would ACCA contain after execution
of the main loop?45