Page 139 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 139
! 16 Chapter 4 Assembly Language Programming
org 800 ; put at the beginning of SRAM
OPTR: ds. w 1 ; pointer to object code that was generated
LINE i ds .b 1 ; line number (line < 10 )
LINEBGN: ds . w 1 ; address of first character in line of source code
*
* listing subroutine : X points to the listing line
LIST: Idab #0 ; generate ASCII character "zero"
addb #LINE ; add binary line number (line < 10 )
bsr DUTCH ; output line number
Idb #$20 ; output space
bsr DUTCH
Idy Optr ; get pointer to object code
Ida 1, y+ ; y points to where next byte will be put,
bsr OutHex ; output two previously stored bytes of object code
Idaa l,y+
bsr OutHex
styr OPTR ; save pointer to object code
Idab #$20 ; output space
bsr DUTCH ;
Idy LINEBEGIN ; get beginning of source line
Loop: Idab 2, y+ ; get character, advancer to next character
bsr DUTCH ; output character
cpb #d ; up to and including c.r.
bne LOOP
return ; return
*
OUTHEX: tab ; duplicate byte to be printed
Isrb ; shift right four bits
bsr OUTHEX 1 ; output hex number that was in high nibble of A
tab ; fall through, output low nibble of A
OUTHEX l:andb #$fO ; clear away all but low nibble
cmpb #9 ; if low nibble is a letter (A - F)
bis OUTHEX2 ; then adjust the output
addb #7 ; by adding 1 to the input
OUTHEX2 : addb #0 ; convert to ASCII character
DUTCH: stab 1, x ; store the character in the listing, move pointer
rts ; return to caller
Figure 4.28. Line Print Subroutine with Errors
28. Write a shortest subroutine PAS SI for "SA2" that will fill the symbol table, if a
symbol appears more than once; it prints the line number, the word "error," and the error
number 1; and it terminates with carry clear; otherwise, it terminates with carry set. The
line number is to be printed in hexadecimal using OUTHEX (Problem 27). Assume the
answers to Problems 24,25, and 27 are "included" (don't write them).