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

110                              Chapter 4 Assembly Language Programming


                   ABSENTRY ENT                         ABSENTRY     ENT
                   ORG         $800                     ORG          $800
           ENT: LDD            K,PCR             ENT: LDD            <K,PCR
                   ADDD        #3                       ADDD         #3
                   STD         K,PCR                    STD          <K,PCR
                   SWI                                  SWI
           K:      DS          1                 K:     DS           1
                     a) Illegal Forward Reference     b) Legal Forward Reference

                      Figure 4.22. Program with Relative Address Reference

         9 . Figure 4.22 shows two programs that attempt to add 3 to variable K, However,
         Figure 4.22a may not assemble because of an illegal forward reference; or, if it does
         assemble, it produces less efficient code than you can produce by hand. Explain why this
         problem might occur. Figure 4.22b illustrates a solution to the problem, by using the
         "<" operator. Explain why this will assemble to produce efficient code.

         10. Figure 4.23 shows three programs that attempt to add 3 to the variable K. However,
         Figure 4.23a may not assemble because of an illegal forward reference; or, if it does
         assemble, it produces less efficient code than you can produce by hand. Explain why this
         problem might occur. Figure 4.23b illustrates a solution to the problem by changing the
         forward to a legal backward reference. Explain why this assembles correctly. Figure 4.23c
         illustrates another solution to the problem, by using the "<" operator. Explain why this
         will assemble directly. Finally, explain why programmers generally put their data in
         front of (at lower addresses than) the program(s) that use the data,
         11. Write a shortest assembly-language (source code) program that calls subroutine
         GET, which inputs a character, returning it in accumulator A, and stores these characters
         in the vector K as in Figure 4.8. Consecutively input characters are put in consecutive
        bytes until a carriage return is input; then a null (0) byte is written in K.

         12. Write a shortest assembly-language (source code) subroutine that moves characters
         as in Figure 4.9 but converts lower case letters to upper case letters as it moves them,

                 ORG        $800             ORG    0               ORG $800
           ENT: LDD         K         K:     DS     1         ENT: LDD <K
                 ADDD      #3         *                             ADDD #3
                 STD        K         ENT: LDD      K               STD <K
                 SWI                         ADDD #3                SWI
                 ORG        0                STD K                  ORG 0
           K: DS            1                SWI              K:    DS    1
         a) Illegal Forward Reference  b) Legal Backward Reference c) Legal Forward Reference

                     Figure 4.23. Program with Direct or Page Zero Reference
   128   129   130   131   132   133   134   135   136   137   138