Hardware Reference
In-Depth Information
ldx
array
; place the starting address of array in X
movw
0,sum
; initialize sum to 0
ldy
N
; initialize loop count to N
loop
ldab
1,x 1
; place one number in B and move array pointer
sex
B,D
; sign-extend the 8-bit number to 16-bit
addd
sum
; add to sum
std
sum
; update the sum
dbne
y,loop
; add all numbers to sum yet?
swi
; return to monitor
end
At first look, this program appears to be fine and should work. After assembling the pro-
gram, we download it onto the demo board and get the following screen output:
. load
....
done
.
It is a good idea to make sure that the program has been downloaded onto the demo board
by using the asm command.
+ asm 1500
xx:1500 FE1000 LDX $1000 .
xx:1503 180400001014 MOVW $0000,$1014 .
xx:1509 DD14 LDY $0014 .
xx:150B E630 LDAB 1,X 1 .
xx:150D B714 SEX B,D .
xx:150F F31014 ADDD $1014 .
xx:1512 7C1014 STD $1014 .
xx:1515 0436F3 DBNE Y,$150B .
xx:1518 3F SWI .
Indeed, the program is downloaded correctly. The next thing to check is to make sure that
the array data is downloaded correctly by using the md command.
+ md 1000 1010
1000 02 04 06 08 - 0A 0C 0E 10 - 12 14 16 18 - 1A 1C 1E 20 . . . . . . . . . . . . . . .
1010 22 24 26 28 - 00 00 B9 A9 - 2A CA FA DB - AC DA 18 97 “$&(. . . .*. . . . . . .
.
Again, we are convinced that the data array has been downloaded correctly. The array is
stored at locations from $1000 to $1013. The variable sum occupies the memory locations from
$1014 to $1015. Since the program has not been run yet, these 2 bytes contain 0s.
The next thing to do is to run the program. This program should run to the swi instruction
and stop. The screen should look as follows:
+ g 1500
User Bkpt Encountered
PP PC
SP
X
Y
D 5 A:B
CCR 5 SXHI
NZVC
38 1519
3C00
0213
0000
FF:07
1001
1000
xx: 1519
88F4
EORA
#$F4
.
 
Search WWH ::




Custom Search