Page 144 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 144
5.1 Cross Assemblers and Downloaders 121
Figure 5.1. Loader Record
S-records are generally used by Motorola and other microcontroller vendors to store
loader records, because ASCII character strings are easy to store on disks and send
through a personal computer's communication software to the target microcontroller. S-
records are essentially character strings made of several fields that identify the record type,
record length, memory address, code/data, and checksum. Each byte of binary data is
encoded as a 2-character hexadecimal number; the first character represents the high-order
four bits, and the second represents the low-order four bits of the byte. An S-record's
fields are shown in Figure 5.2, and Table 5.1 explains the content of each of the S-
record's fields. Each record may be terminated with a carriage return, line feed, or both.
Additionally, an S-record may have an initial field to accommodate other data such as line
numbers generated by some time-sharing systems. Simple downloaders use only three of
eight types of S-records: SO, SI, and S9 records. The SO record generally contains header
information. All data before the first SI record is ignored. Thereafter, all code/data records
must be of type SI, until the S9 record terminates data transfer,
An SO record, which is a header record, is ignored by the downloader, but the cross-
assembler may write in it any descriptive information identifying the following block of
S-records. The SO record address field is normally zeroes. An SI record contains code/data
and the 2-byte starting address at which the code/data is to reside. An S9 record terminates
SI records. Its address field may optionally contain the 2-byte address of the first
instruction to be executed. If an S9 record doesn't specify an address, the first entry point
specification encountered in the object module input is used. There is no code/data field.
A short program, whose listing is shown in Figure 5.3a, generates the S-record in
Figure 5.3b. This simple program has only one SI and the terminal S9 records, which
are explained following the figure. Generally, programs have several SI records.
The S1 code/data record begins with the ASCII characters S1, indicating a code/data
record of length $16 bytes, to be loaded at the 2-byte address $0820. The next 20
character pairs are the ASCII bytes of the actual program code/data. In this assembly
language example, the hexadecimal opcodes of the program are written in sequence in the
code/data fields of the SI records. The first byte is B6, and the second byte is 08 .
Compare this S-record string in Figure 5.3b with the listing in Figure 5.3a.
TYPE RECORD LENGTH ADDRESS CODE/DATA CHECKSUM
Figure 5.2. An S-Record