Page 147 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 147
124 Chapter 5 Advanced Assemblers, Linkers, and Down loaders
.pgm: SECTION
XDEF ENTRY ; Make externally visible
XREF FUN, N ; Use externally defined names
*
ENTRY: LDS #$BFF ; First initialize stack pointer
LDAA N ; Access external variable
JSR FUN ; Call external subroutine
c. Another program section in file Programs .asm
Figure 5.4. Continued
For example, JSR FUN might occur in a section . pgm in one file, but the code for
subroutine FUN is in a different section . text in another file. FUN is declared, in each
file where it is used, in an XREF directive. In the file where the FUN subroutine is
written, label FUN would be declared in an XDEF directive. Labels used by more than one
file are similarly declared where defined (with XDEF) and where used (with XREF).
The SECTION directive's label is the name of the section, which is used in the
parameter file that controls linking. Figure 5.5 illustrates a parameter file that directs
the linker to put certain sections in certain parts of memory. If two or more sections
have the same name, the linker appends them together, forming a larger section that is
allocated in memory as a whole. A SECTION directive may have the word SHORT as an
operand; this means that the section is on page zero and may use page-zero addressing.
The linker requires, as a minimum, sections with names .data and .text.
The parameter file simply tells the linker what files are output from it and input to
it. This parameter file uses C syntax for comments and constants. The parameter file
declares memory segments, which are areas of memory available for assembly-language
sections, and then declares what sections are put in which segments. Finally, parameter
file statements tell where execution begins and what to put in the target's interrupt
vectors, including the reset vector. Interrupt and reset vectors are discussed in Chapter 11,
LINK Program. abs /* the linker will write a file called prog.abs */
NAMES /* list all assembler output files input to the linker */
Programl.o Program2.o Programs.o
END /* several assembler files can be read: end with END */
SEGMENTS /* list all segments, read/write permission & address ranges */
ROM = READ_ONLY 0x800 TO Ox9FF /* a memory segment */
RAM = READ_WRITE OxAOO TO OxBFF /* a memory segment */
END /* several segments can be declared: end with END */
PLACEMENT /* list all sections, in which segments they are to be put */
. text, . pgm INTO ROM /* puts these sections into segment ROM */
.data INTO RAM /* puts a section called .data into segment RAM */
END /* several segments can be filled with sections: end with END */
IN IT ENTRY /* label of first instruction to be executed */
VECTOR ADDRESS OxFFFE ENTRY /* puts label ENTRY at OxFFFE */
Figure 5.5. A Parameter File