Page 337 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 337

314                                   Chapter 10 Elementary Data Structures


         1 9. Write a shortest subroutine GETS that puts three characters into B (first character)
         and Y (second and third character) pointed to by X, and moving X past them and a next
         space or carriage return. Write a shortest subroutine CHKEND that reads three characters
         using subroutine GETS, and checks for the characters "END". Assume the calling
         subroutine has not pushed anything on stack, so if "END" is read, return by pulling two
         bytes from the stack and executing rts, so as to terminate the calling subroutine,
         otherwise return by just executing rts as usual to return to the calling subroutine.
         These subroutines are to be used in problem 21.
         2 0. Write a shortest subroutine FIND which searches a binary tree, pointed to by X for
         three letters, B:Y as returned by GETS of problem 19. The binary tree nodes contain a
         3-byte character string, a one-byte value, and two two-byte addresses, the first of which
         points to a left son, and the other points to a right son. If the three letters are found,
         return with X pointing to the beginning of the node, else if the letters are lower in the
         dictionary than the last node searached in the tree, X points to the left son field of the last
         node, but if higher, X points to the right son field of the last node. This subroutine is to
         be used in problem 21.


         21. Write a 6812 assembler program using linked lists, able to assemble programs
         having the following specifications.

             (a) The operations will be encoded in the left two bits of a one-byte opcode: LDA is
             00, ADD (for ADDA) is 01, STA is 10, and SWI is 11. There will also be
             directives DCB and END.

             (b) At most six lables can be used, each of which is exactly three uppercase letters
             long. Operands will be encoded in the right six bits of a one-byte opcode.
             (c) Only direct addressing can be used with instructions, which will be coded in the
             right 6 bits of the instruction, and only hexadecimal numbers, beginning with $,
             can be used with the DCB directive.
             (d) The input line will have a fixed format: label (3 characters), space, instruction
             mnemonic (three characters), space, address (3 characters or 2-digit hexadecimal
             number prefixed with a $) ending in a carriage return. There are no comments, and,
             if a label is missing, it is replaced by 3 spaces.

             (e) The program will have from 1 to 10 lines, ending in an END directive.

             (f) The source code has no errors (i.e., your assembler does not have to check
             errors). The origin is always zero.

             Your assembler will have the source code prestored as a character array TEXT, 10
             rows by 12 columns, and will generate an object code string OBJ up to 10 bytes
             long. No listing will be generated. The assembler should be able to at least
             assemble the following two programs, shown on the left and shown on the right.
   332   333   334   335   336   337   338   339   340   341   342