Hardware Reference
In-Depth Information
Checking the resultant sum, we can see that it ($FF07) is incorrect. The correct answer
should be $1A4 (or 420). The sum can be found by using the md command as follows:
+ md 1010
1010 22 24 26 28 - FF 07 B9 A9 - 2A CA FA DB - AC DA 18 97 “$&(. . . .*. . . . . . .
.
Since this program is short, we can trace through it. To trace this program, we set the pro-
gram counter value to the start of the program ($1500) as follows:
+ pc 1500
PP PC
SP
X
Y
D 5 A:B
CCR 5 SXHI
NZVC
38 1500
3C00
0213
0000
FF:07
1001
1000
xx: 1500
FE1000
LDX
$1000
.
Trace one instruction at a time.
+ t 1
PP PC
SP
X
Y
D 5 A:B
CCR 5 SXHI
NZVC
38 1503
3C00
0204
0000
FF:07
1001
0000
xx: 1503
180400001014
MOVW $0000,$1014
.
The executed instruction is ldx array. The purpose of this instruction is to place the starting address
of the array into X. After the execution of this instruction, the value of X should change to $1000.
However, the instruction trace shows otherwise. This is because of the incorrect use of the addressing
mode. Change the instruction to ldx #array, rerun the program, and the sum is still incorrect.
+ md 1010
1010 22 24 26 28 - FF F0 B9 A9 - 2A CA FA DB - AC DA 18 97 “$&(. . . .*. . . . . . .
.
Trace the program again. This time we trace up to the second instruction and examine the
contents of sum .
+ t 2
PP PC
SP
X
Y
D 5 A:B
CCR 5 SXHI
NZVC
38 1503
3C00
1000
0000
FF:F0
1001
0000
xx:1503 180400001014
MOVW $0000,$1014
PP PC
SP
X
Y
D 5 A:B
CCR 5 SXHI
NZVC
38 1509
3C00
1000
0000
FF:F0
1001
0000
xx:1509 DD14
LDY
$0014
+ md 1010
1010 22 24 26 28 - FF 00 B9 A9 - 2A CA FA DB - AC DA 18 97 “$&(. . . .*. . . . . . .
.
At this point, the value of sum should be changed to 0 because the second instruction in-
tends to initialize it to 0. Again, the addressing mode is wrong. The correct instruction should
be movw #0,sum. This is not easy to figure out by looking at the program. Rerun the program
and display the contents of sum .
+ load
*
+ g 1500
Search WWH ::




Custom Search