EXPLAINING THE INTEL HEX FILE

SECTION 8.3: EXPLAINING THE INTEL HEX FILE

Intel hex file is a widely used file format designed to standardize the loading of executable machine codes into a ROM chip. Therefore, loaders that come


Figure 8-8. List File For Test Program (Assembly)

with every ROM burner (programmer) support the Intel hex file format. While in many newer Windows-based assemblers the Intel hex file is produced automatically (by selecting the right setting), in a DOS-based PC you need a utility called OH (object-to-hex) to produce that. In the DOS environment, the object file is fed into the linker program to produce the abs file; then the abs file is fed into the OH utility to create the Intel hex file. While the abs file is used by systems that have a monitor program, the hex file is used only by the loader of an EPROM programmer to load it into the ROM chip.


Program list file for test program

The list file for the test program is given in Figure 8-8. The LOG and OBJ fields in Figure 8-8 must be noted. The location is the address where the opcodes (object codes) are placed. The LOG and OBJ information is used to create the hex file. Next, we will analyze the hex file belonging to the list file of Figure 8-8.

Analyzing Intel hex file

Figure 8-9 shows the Intel hex file for the test program whose list file is given in Figure 8-8. Since the ROM burner (loader) uses the hex file to download the opcode into ROM. the hex file must provide the following: (1) the number of bytes of information to be loaded, (2) the information itself, and (3) the starting address where the information must be placed. Each line of the hex file consists of six parts. In Figure 8-9. we have separated the parts to make it easier to analyze. The following describes each part.



Figure 8-9. Intel Hex File Test Program as Provided by the Assembler


  1. “:” Each line starts with a colon.



    1. CC, the count byte. This tells the loader how many bytes are in the line. CC
      can range from 00 to 16 (10 in hex).

    2. AAAA is for the address. This is a 16-bit address. The loader places the first
      byte of data into this memory address.

    3. TT is for type. This field is either 00 or 01. If it is 00, it means that there are
      more lines to come after this line. If it is 01, it means that this is the last line
      and the loading should stop after this line.



5. DD D is the real information (data or code). There is a maximum of 16


bytes in this part. The loader places this information into successive memory locations of ROM.

6. SS is a single byte. This last byte is the checksum byte of everything in that
line. The checksum byte is used for error checking. Checksum bytes are dis
cussed in detail in Chapters 6 and 7. Notice that the checksum byte at the end
of each line represents everything in that line and not just the data portion.

Now, compare the data portion of the Intel hex file in Figure 8-9 with the information under the OBJ field of the list file in Figure 8-8. Notice that they are identical, as they should be. The extra information is added by the Intel hex file formatter. You can run the C language version of the test program and verify its operation. Your C compiler will provide you both the list file and the Intel hex file if you want explore the Intel hex file concept.


Examine the next three examples to gain an insight into the Intel hex file.

Example 8-3

From Figure 8-9, analyze the six parts of line 3.

Solution:


After the colon (:) we have 07, which means that seven bytes of data are in this line. 0020H is the address at which the data starts. Next, 00 means that this is not the last line of the record. Then the data, which is seven bytes, is as follows: DB FE DC FA DD F6 22. Finally, the last byte, 35, is the checksum byte.


Example 8-4


Verify the checksum byte for line 3 of Figure 8-9. Verify also that the information is not corrupted.


Solution:


07 + 00 + 20 + 00 + DB + FE + DC + FA + DD + F6 + 22 = 5CBH. Dropping the carries (5) gives CBH, and its 2′s complement is 35H, which is the last byte of line 3. If we add all the information in line 3, including the checksum byte, and drop the carries we should get 00. 07 + 00 + 20 + 00 + DB + FE + DC + FA + DD + F6 + 22 + 35 = 600H

Example 8-5

Compare the data portion of the Intel hex file of Figure 8-9 with the opcodes in the list file of the test program given in Figure 8-8. Do they match?


Solution:


In the first line of Figure 8-9, the data portion starts with 75H, the opcode for the instruction “MOV”, as shown in the list file of Figure 8-8. The last byte of the data in line 3 of Figure 8-9 is 22, which is the opcode for the “RET” instruction in the list file of Figure 8-8.


SUMMARY

This chapter began by describing the function of each pin of the 8051. The four ports of the 8051, PO, PI, P2, and P3, each use 8 pins, making them 8-bit ports. These ports can be used for input or output. Port 0 can be used for either address or data. Port 3 can be used to provide interrupt and serial communication signals. Then the design of the DS89C4xO-based trainer was shown. We also explained the Intel hex format.

Next post:

Previous post: