Intel HEX

The EdSim51 Simulator handles machine code files in the Intel HEX format. You can load and save HEX files.

Now you can write C code for the 8051, using a C compiler for the 8051 such as Keil, and then import that code to the EdSim51 Simulator via the Intel HEX file format. You’ll need to ensure your C compiler outputs an Intel HEX file. To see how to do this for Keil uVision, click here.

Intel HEX

Intel HEX is a standard format for writing machine code to a regular text file. An example of an Intel HEX file is shown below.

Apart from the colon at the beginning of each line, the file contains only numbers, in hexadecimal form (0 through F). Each line contains a record. Each record is divided into six parts. The six parts are explained in the table below.

Loading Intel HEX Files

To load a HEX file, click the Load button and in the file chooser that appears, select the Intel HEX Files option from the Files of Type: menu. Files with the .hex extension will be displayed.

Usually, HEX files are saved with .hex extension. However, this is not a necessity. The EdSim51 Simulator scans every file as it is loaded. If the file meets the Intel HEX format (described above) it is then disassembled and displayed as assembly code. If the file is not in HEX format it is simply loaded as a text file.

The image above shows part of a disassembled Intel HEX file (it is, in fact, the disassembly of the HEX file shown above).

Saving Intel HEX Files

Click on the Save button to save a file. In the window that opens, the user can select, from the Files of Type: menu, one of three choices.

  • Assembly Files – The assembly source code is saved without modification. It is saved as a text-only file.
  • Intel HEX Files – The machine code in code memory is saved to a text file in Intel HEX format (format explained above).There are two important points to be remembered when saving in HEX format:
    • Usually, when writing assembly code, the programmer uses labels, assembler directives (example, PSW for the address of the Program Status Word), etc. None of this information is saved in HEX format. HEX format saves only the code that resides in code memory. The EdSim51 Simulator keeps track of what areas of code memory the programmer is using and only those areas are saved in the HEX file.
    • If the source code has not assembled without errors it cannot be saved in HEX format. If you attempt to save unassembled code in HEX format an error message will be displayed.
  • Assembly Files and HEX Files – Perhaps you want to save your code in both formats. If so choose this option. You need only provide the name of one of the files to be saved. Two separate files are then saved; one without modification and with either .a or .asm extension, the other in HEX format with .h. The name of the second file is generated automatically from the first. For example, if you provide example.asm as the file name, the second file name will be example.hex. If you provide example.hex as the file name, the second file name will be example.asm.

Write C code for the 8051 and import the machine code into the EdSim51 Simulator.

You can write C program for the 8051 using one of many 8051 C compilers. You will need to have the C compiler output a HEX file. You can then open this HEX file and test your program in the EdSim51 Simulator.

If, for example, you are using Keil’s uVision IDE you can get a HEX file output by going to Project>Options for Target and clicking on the Output tab. Check the Create HEX File checkbox and click Enter.