Page 137 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 137
! 14 Chapter 4 Assembly Language Programming
For problems 4.24 to 4.30, we will write parts of a "Sample Assembler" SA2 with the
following overall specifications:
a) The target computer has only one 16-bit accumulator (A), one condition code
(N), and 256 16-bit memory words. Each memory address is for a 16-bit word,
b) The target computer's opcodes will be LD (0), AD (1), ST (2), and BM (3)
(similar to 6812 opcodes LDAA, ADDA, STAA, and BMI). The assembler has a
directive DC, for "define constant byte," that has one four-digit hexadecimal
number operand, and EN, which is the end of the source code.
c) A source code line can have a 3-character label or not (DC must have a label),
one or more spaces, an opcode or assembler directive, one or more spaces, an
operand, and optionally, one or more spaces and comments, ending in a carriage
return. Permissible addressing modes are 8-bit direct for LD, AD, and ST, and
signed 8-bit relative addressing for BM. So each instruction is 2 bytes.
d) The assembler is to be run on the 6812 host. The source code can have errors,
and error numbers are printed. The source code will be stored in a constant
ASCII string SOURCE, which is null terminated, the object code, stored in 16-
byte vector OBJECT, is indexed by an 8-bit variable LCNTR; and the listing,
stored in 80-byte vector LISTING, is pointed to by 16-bit variable LPTR.
Finally, 8-bit variable LINE is the source code line number being read.
e) All labels will be exactly three characters long. The symbol table, stored in 16-
byte vector LABELS consists of four 4-byte rows for each symbol, each row
comprising three characters followed by a one-byte address. The number of
symbols currently in the table is in 8-bit variable SIZE.
2 4, Write DS assembler directives needed to declare all storage locations for "SA2."
25. Correct the assembly-language program in Figure 4.27. Do not change any lines
that are already correct. The calling routine, part of pass 1 of an assembler, checks the
symbol table for a matching label and enters the label if no match is found. The symbol
table contains this label, which is three ASCII characters, and the associated value, which
is 1 byte. This program consists of a calling routine and a subroutine FINDLBL for
"SA2," used in Problems 28 and 29, to compare a string of assembler source code
characters at SPTR against known labels in the symbol table; if a match is found, the
symbol table row number in which it is found is returned in accumulator A with carry
clear; if not found, it returns with carry set. The program must assemble in Hi ware and
run correctly in the 6812 'B32chip.
2 6. Write a shortest subroutine GETOPCD for "SA2," used in Problem 29, to compare a
string of assembler source code characters against the permissible opcodes, returning the
opcode or value of the defined constant in accumulator D, with carry set if found, and
returning with carry clear if no match is found.