|
Intel
HEX Format |
|
|
|
|
|
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. |
|
:10000000C29FD29EE587D2E7F587758920758DFD61 :10001000758BFDD28E7530617531627532637533C3 :10002000007830E6600EA2D092E7F599083099FD8D :06003000C29980EF80FE82 :00000001FF
|
|
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. |
|
|
character 1 |
marker |
Every record must begin with : |
characters 2-3 |
length |
The two bytes immediately after the colon state the
number of machine code bytes in the record. Therefore, the maximum
number of machine code bytes in a record is 256. |
characters 4-7 |
address |
Bytes 4 through 7 state the code memory address of the
first machine code byte in the record. |
characters 8-9 |
type |
There are three types:
- 00
- record contains normal internal memory machine code.
- 01
- end of file - this should be the last record in the file - there are
no machine code bytes with a 01 type record.
- 02
- indicates the record contains machine code for extended (external)
memory - since the EdSim51 Simulator does not deal with external memory
any 02
type records will be ignored (if such records exist a warning will be
displayed when the file is loaded into the Simulator).
|
data begin at character 10 |
data |
If there are any data bytes, they begin immediately
after byte 9 - maximum number of bytes per record is 256. |
last 2 characters |
checksum |
The last two bytes are a checksum that are used to
detect errors in the preceding record bytes (excluding the colon). The
checksum is calculated by adding all the bytes together. 8-bit addition
(the 9th carry bit is ignored) is used. The checksum is then the
difference between this 8-bit sum and 256. If you look at the end of
file record in the above example (the last line) you will notice that
adding up all the bytes (excluding the colon and the last two bytes
which are the checksum) you get 1. Then subtract this from 256 and you
get 255, which is FF in hex. As you can see, this is the checksum for
that record. For more information, click here. |
|
|
|
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 (as shown in the images above). 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 opposite 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. |
|
|
|
|
|
Copyright
(c)
2005-2013 James
Rogers
|