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

5.2 Relocatable Assemblers and Loaders                              ! 23

        5.2 Relocatable Assemblers and Loaders


        The downloader described in the previous section is sometimes called an absolute loader,
        because the location of the program is completely specified by the assembler that writes
        S-records. There is a limitation with an absolute loader. Suppose that you have written a
        program that uses a standard subroutine from a collection provided by Motorola or a third
        party. You have to copy it physically into your program, perhaps changing the ORG so
        that it does not overlap with your program, and then assemble the whole package. What
        you might like to do instead is to be able to assemble your program separately and then
        have the loader take your machine code, together with the machine code of any standard
        subroutines already assembled, and load them all together in consecutive RAM locations
        so that memory bytes would not be wasted.
            To achieve merging of programs that are assembled separately, assemble each
        program segment as if it began at location zero. Each such program segment is called a
        relocatable section. A linker program determines the sizes of each section and allocates
        nonoverlapping areas of target memory to each. Each section's addresses are then adjusted
        by adding the section's beginning address to the address within the section.
            Assembler directives, listed in Table 5.2, are used to name sections and identify
        labels that are declared in other files or are to be made available for use in other files. See
        Figure 5.4. A relocatable section begins with a SECTION directive. In each section,
        certain symbols would have to be declared in XDEF and XREF directives.


                              Table 5.2. Relocation Directives














                 .data: SECTION
                          XDEF       N, V            ; Make N, V externally visible
                 N:       DS         1               ; Declare a global variable
                 V:       DS         50              ; Declare a global vector
                            a. A data section in file Program! .asm.

                 .text: SECTION
                          XDEF       FUN             ; Make FUN externally visible
                 *
                 FUN:     RTS                        ; Should be replaced by full sub.
                          b. A program section in file Program2.asm

                       Figure 5.4. Sections in Different Source Code Files
   141   142   143   144   145   146   147   148   149   150   151