Hardware Reference
In-Depth Information
Figure 3.18
■
Screen after running the eg2_13 program and displaying the result
These six lines tell us that
•
The index register contains hex value $04D2 (equal to decimal 1234) and is the
correct quotient.
•
The memory location at $1014 contains hex value $35 and is the ASCII code of 5.
•
In the next division, the number to be divided by 10 will be 1234.
•
The next instruction to be executed is
ldx #$0A.
Step 2
Trace the next two instructions
.
Oops! We find one error. The double accumulator D does
not contain the value 1234 (it contains $35 instead) before the
idiv
instruction is executed.
We forgot to swap the value in index register X with double accumulator D before
performing the second division!
+
t
PP PC
SP
X
Y
D
5
A:B
CCR
5
SXHI
NZVC
38 1512
3C00
000A
1010
00:35
1001
0000
xx: 1512
1810
IDIV
+
t
PP PC
SP
X
Y
D
5
A:B
CCR
5
SXHI
NZVC
38 1514
3C00
0005
1010
00:03
1001
0000
xx: 1514
CB30
ADDB
#$30
.
Step 3
Fix the error by inserting the
xgdx
instruction before the
ldx #$0a
instruction and rerun
the program. After rerunning the program, check the contents at $1000 to $1004 again.
The last few lines on the screen of the terminal window would be as follows:
Search WWH ::
Custom Search