Page 239 - Programming Microcontrollers in C
P. 239
224 Chapter 5 Programming Large 8-Bit Systems
the correct location in memory, and it will also place the addresses of
the designated vectors in the proper locations in the table.
The start-up routine mentioned earlier is shown below. This
routine is patterned after one provided with the compiler. This
assembly language program contains all of the code necessary to
begin the operation of the C program to which it is linked. But note
this point on syntax: within C, all function and memory names
generated by the code are modified by the addition of an underscore
_ at the beginning of the name. Therefore, if the function main() in
the C program were to be referred to by an assembly program, the
assembly program would be required to use _main. You will notice
that there are many names beginning with both single and double
underscores. For example _main has a single underscore, and
__memory has a double underscore in the external statement that
follows. Whenever an assembly language memory location or function
name has underscores preceding the name, one of the underscores
must be discarded when this same memory or function name is used
in a C program to be linked to the module.
Here you see an example of why the programmer should not use
an underscore for the first character of a name. The compiler writer
assumes complete freedom to use the single underscore to begin any
name needed by the operation of the compiler, and the programmer
should concede this freedom to the compiler writer by avoiding the
use of the underscore for the first character of a name anywhere in
his program.
An example of this linkage has already been seen. In a previous
section where the vector table was programmed, the entry point into
the program was the function _stext(). Note in the code that follows
that the function name in the assembly language part of the program is
__stext with a double underscore. This start-up routine has been
modified for use with a program that we will use later in the text. The
most significant modification is the first two executable instructions
which set the y register to the beginning of the I/O register memory
area and then sets bits 0 and 1 of the location offset 36 (0x24) from the
y register content. These instructions set the prescaler of the timer
counter to 4 so that the timer will increment at the slowest possible
rate. These two instructions modify the contents of TFLG2 and they
must be changed within 64 bus cycles after the microcontroller exits
reset. These changes and others needed in the INIT register, the