Data&Docs Home

Motorola S-record Format

Motorola's S-record format for output modules was devised for the purpose of encoding programs or data files in a printable (ASCII) format. This allows viewing of the object file with standard tools and easy file transfer from one computer to another, or between a host and target. An individual S-record is a single line in a file composed of many S-records.

S-Records are character strings made of several fields which specify the record type, record length, memory address, data, and checksum. Each byte of binary data is encoded as a 2-character hexadecimal number: the first ASCII character representing the high-order 4 bits, and the second the low-order 4 bits of the byte.

The 5 fields which comprise an S-record are defined as follows:

Field Characters Description
1 Type 2 S-record type - S1 or S9.
2 Record length 2 The count of the bytes (character pairs) in the record, excluding the type and record length.
3 Address 4 The 2-byte address at which the data field is to be loaded into memory.
4 Data 0-2n From 0 to n bytes of executable code, or memory loadable data. The number of data bytes (n) is typically 16.
5 Checksum 2 The least significant byte of the one's complement of the sum of the values represented by the pairs of characters making up the record length, address, and data fields.

Each record may be terminated with a CR/LF/NULL. Accuracy of transmission is ensured by the record length (byte count) and checksum fields. Because the data field is composed of character pairs, each pair being one 8-bit byte, S19 files are commonly used with 8-bit processors. Because the address field is only four characters, S19 files are restricted to a 64 kilobyte address space.

Eight types of S-records have been defined to accommodate various encoding, transportation, and decoding needs. Lucid programmers use the 8-bit data types, the S1 and S9:

S1 A record containing data and the 2-byte address at which the data is to reside.
S9 A termination record for a file of S1-records. Only one S9-record is allowed per file and it must be the last line of the file. The address field for directly executable code may optionally contain the 2-byte address of the instruction to which control is to be passed. For ROM data the S9 address field is usually 0000. There is no data field.

The following is a typical S-record module:


The module consists of four S1 data records and one S9
termination record. The first S1 data record is explained 
as follows:

    S1    S-record type S1, indicating a data record to be
          loaded/verified at a 2-byte address.

    13    Hex 13 (decimal 19), indicating 19 character pairs,
          representing 19 bytes of binary data, follow.

    00    Four-character 2-byte address field:  hex address 0000,
    00    indicates location where the following data is to be loaded.

          The next 16 character pairs are the ASCII bytes
          of the actual program data.

    2A    Checksum of the first S1-record.

The second and third S1 data records also contain $13 character
pairs each. The fourth S1 data record contains 7 character pairs.

The S9 termination record is explained as follows:

    S9    S-record type S9, indicating a termination record.

    03    Hex 03, indicating three character pairs (3 bytes) to follow.

    00    Four-character 2-byte address field.

    FC    Checksum of S9-record.