Page 136 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 136
PROBLEMS 113
ORG 0
COUNT DS 0 Number of characters changed
STRING DC.B " A b c . 1 String to be converted
BEGIN DC.B STRING Starting address of string
S DC.B STRING-BEGIN The length of the string
*
ORG #$800
LD A,S String size into A
LEAY #COUNT Counter address into Y
LDX BEGIN X points to STRING
CLR COUNT initialize counter
LOOP LDAB 0,X Get next character
CMPB #'a Compare character with "a"
BLOW L if lower, go to L
CMPB #97 Compare character with "z"
BLS L if higher, go to L
ANDB #~$20 Change by clearing bit 5
INC 0,Y increment counter
L STAB ,X+ Put back letter
DEC A Decrement number left
BNE LOOP Check next character
SWI
Figure 4.25. Another Program with Errors
22. Correct the assembly-language program in Figure 4.24 so that each line, and the
whole program, would be accepted by the Motorola assembler without an assembler
error. Do not change any lines that are already correct. The program replaces each of the
N 8-bit two's-complement numbers with the absolute value of the number, rounded
down to the next lower even number. For example, + 4 is replaced with + 4, - 4 with +
4, - 5 with + 4, + 5 with + 4, and so on.
2 3. Correct the assembly-language program in Figure 4.25 so that each line would be
accepted by the Motorola assembler without an assembler error. The program takes a
sequence STRING of ASCII characters and converts all of the lowercase letters in
STRING to uppercase letters while finding the number COUNT of letters that were
converted. Do not change any lines that are already correct.
LD ALF
Location Contents Mnemonics
AD BET
SS GAM
0 0003 LD 3
1 0104 AD 4 ALF DC 0012
2 0205 ST 5 BET DC 0034
GAM DC 0000
a. Machine code b. Source code
Figure 4.26. Machine and Source Code for SA2