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

106                              Chapter 4 Assembly Language Programming


           *;(;**;};*****.•(;**************
           *        Get an Opcode
           *        entry: B is mnemonic opcode character
          *         exit:  A is opcode
          *                X is unchanged
           +
          GETOPCD: CLRA         ; if exit next, return zero as machine opcode
                    CMPB #'L' ;Load
                    BEQ    GO1
                    LDAA #$40 ; if exit next, return $40 as machine opcode
                    CMPB #'A';Add
                    BEQ    G01 ; if it isn't D, L, or A, it must be S, for Store
                    LDAA #$80; return $80 as machine opcode
          G01:      RTS

                           Figure 4.19. Subroutine to Get the Opcode



            FINDLBL (Figure 4.20) begins by setting up X for a loop; the loop searches each
        row of the symbol table, which was created in PASS1, until it finds a match. It searches
        each row of the symbol table. Because we assume there are no errors in our source code,
        it will always succeed in returning the value for the matching label.
            GETHEX (Figure 4.21) calls an internal subroutine Gl to translate an ASCII
        character to a hexadecimal value. Gl uses the fact that ASCII letters "0" to "9" are
        translated into hexadecimal numbers by subtracting the character value of "0" from them,
        and the remaining ASCII characters "A" to "F" are translated into hexadecimal by further
        subtracting 7 from the result (because there are seven letters between "9" and "A" in the
        ASCII code). The first value obtained from the first letter is shifted to the high nibble
        and pushed on the stack. When the second value is obtained from the second letter, it is
        combined with the value pulled from the stack.




          ************************ *
          * Find Label
          * entry: label character in B, OP code byte (from GETOPCD) in A
          * exit: ORs symbol's value into A
          *                x is unchanged
          *
          FINDLBL: LDY #LABELS ; y-> first symbol table row
          F1:       CMPB 2, y+ ; compare first character in B and move to next symbol table entry
                    BNE Fl      ; if mismatch, try next by going to Fl
                    ORAA -1, y ; OR previous row's value into the OP code in A
                    RTS         ; return to caller
                      Figure 4.20. Subroutine to Insert a Label as an Operand
   124   125   126   127   128   129   130   131   132   133   134