Page 138 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 138
PROBLEMS ! 15
origin 800 ; put at the beginning of SRAM
entry SOURCE ; provide entry address to Hiwave
*
LCNTR: ds.w 1 ; 8-bit location counter
SIZE: ds. b ; 8-bit number of symbols
SOURCE: dc.b "ALF DC 7A" f $d,"LBl LD LB2",$d,"LB2 AD LBl,$d
LABELS dc.b 32 ; allocate 32-byte symbol table
*
Idx SOURCE ; get source code string address
bsr FINDLABEL ; look for label
bvs FOUND ; if none found, skip. Note: y -> next symbol entry
movb 1, x+, y+1 ; if found, copy first char from source to symbol table
movd 2, x+, 2, y+ ; then copy 2nd and 3rd characters to symbol table
movb #LCNTR, 1, y + ; and copy location counter into symbol table
add SIZE, 1 ; increase label count
FOUND: bra * ; wait for debugger to stop program
*
FINDLBL: pshx ; save caller's pointer on the stack
leax #LABELS ; x-> first symbol table row
Idab 1, X+ ; get a character from source file
Idy +1, X ; get next two characters from source file
Ida SIZE ; A = number of symbols
branch F2 ; go to end at F2 (in case there are zero items)
*
F1: cpb 4, x+ ; compare first character in B and move to next row
bne F2 ; if mismatch, try next by going to F2
cpy 3, x ; compare second, third character in Y
clra ; clear A and carry indicating success
Idx - 4, x ; make x-> beginning of row found
bra F4 ; exit after balancing stack, putting pointer in Y
F2 : dec a ; count down accumulator A
bpl Fl ; go to Fl to do search if more to come
setc ; set carry to indicate failure
F3: leay SOURCE ; make y-> beginning of row found
pula ; restore caller's pointer from the stack
rts ; return to caller
Figure 4.27. FINDLBL Subroutine with Errors
27. Correct the assembly-language program in Figure 4.28. Do not change any lines
that are already correct. This shortest subroutine LIST for "SA2" prints a line of the
listing at the end of PASS2, after two bytes have been put into the object code. It prints
the decimal line number ( < 10), the hexadecimal object code, and the source code.
OUTHEX prints a binary number n in accumulator A as two digits (the hexadecimal
representation of n). OUTCH places the ASCII character in accumulator A into a line of
the listing, which is pointed to by the X register.