HEX FILE 12 Bit PIC Disassembly

HEX FILE 12 Bit PIC Disassembly

Postby bxdobs » Sun Oct 26, 2014 6:32 am

PIC 12 Bit Instruction Dis-assembler attached (excel 2k3)

PIC Hex File Description

All PIC compilers, be it ASM or High Level C, C++, etc., output their program data in Intel Hex Format.

Intel hex format:

Data Record: ':nnaaaattdddddddddddddddddddddddddddddd...cc'
: = Indicates start of data record
n = Count of number of bytes in record. (in ASCII/HEX)
a = Load address of data record. (in ASCII/HEX)
t = Record type (00=Data, 01=End of file)
d = Actual data bytes in record (in ASCII/HEX)
c = Checksum of count, address, and data. (in ASCII/HEX)

Note: Checksum is computed as two's complement of the eight bit sum of all values from 'nn' to end of data. Two's complement is all bits reversed 0->1 1>0 then add 1

For example, here is a line from a hex file (read using Notepad) <file>.hex


when expanded so it is easier to read:

nn aaaa tt d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df cc
:10 - 0200 - 00 - 00 F0 0C EF 01 F0 5E 01 - FA CF FF F4 66 EF 06 F0 - AC

The data record is broken down in to the following values:
nn = 10 there are nn = 16 bytes of data for this line
aaaa = 0200 the data starts at Address 0200 (see Address Note 2 below)
tt = 00 the Record Type for this line is DATA
d0-f = <dn> bytes of data that start from the Address (See Address Note 1 below)
cc = AC 2's Complement of the sum of all bytes in this line
54 = SUM(10 02 00 00 00 F0 0C EF 01 F0 5E 01 FA CF FF F4 66 EF 06 FO)
AB = complement(54)
AC = AB + 1

Address Note:
There is one key detail to be understood; The Intel Hex File Data Format was designed around BYTE oriented data. PIC Families require a minimum of 2 BYTES per instruction ... this has 2 important ramifications:

1) Each PIC instruction (12 to 16 bits in length) are stored in a LO Byte, HI Byte format

2) The Intel Address is NOT the PIC Instruction Address

Example: PIC Assembly listing from a 12 instruction bit for PIC10F206:
ORG 0x000
0000 0025 movwf OSCCAL
0001 0A80 goto 0x080

ORG 0x080
0080 0000 NOP
0081 0A80 goto 0x80

This listing produces the following Intel HEX file
nn aaaa tt d0 d1 d2 d3 cc
:04 0000 00 25 00 80 0A 4D
:04 0100 00 00 00 80 0A 71
:02 1FFE 00 EB 0F E7
:00 0000 01 FF

The are a few things to Note here:
a) the second line has an intel reference address of 0x100 and NOT 0x0080 (the PIC Instruction address) ... in this case, we could figure out the PIC address provided we know the size of the PIC instruction in BYTES.

b) d0 is 25 the LO byte and d1 is 00 the hi byte of the first PIC instruction

c) the forth line shows the end of file format (tt = 01)

d) the third line for Intel address is 1FFE ... this is address of the PIC Configuration Flags

PIC 10F206
O - OSC = 0x0001 1 = Int 0 = na
W - WDT = 0x0004 1 = On 0 = Off
C - CP = 0x0008 1 = Off 0 = On
M - MCLR= 0x0010 1 = On 0 = Off

PIC Address
0FFF FFEB 1111 1111 1110 1011
PIC 12 Bit DisAssemble.rar
(225.71 KiB) Downloaded 1981 times
Posts: 3
Joined: Sun Oct 26, 2014 5:08 am
PIC experience: Experienced Hobbyist

Return to Getting started with pic's, architecture and overview section

Who is online

Users browsing this forum: No registered users and 2 guests