Electronic – Memory locations in AVR hex file

flashprogramming

I am trying to understand the hex file generated by the AVR Studio. I wrote a code in assembly. The code is as follows:

#include "m328pdef.inc"
.org 33
rjmp reset
reset: 
        add r16,r17
main:
        out DDRB,r16
        rjmp main

The .org is to hard code my code into the memory location 33. Then I checked the generated hex file. That is as follows:

:020000020000FC
:0800420000C0010F04B9FECF5C
:00000001FF

The 2nd line should be of interest. The address where this is stored is 0042. How so?
Can you kindly clarify my understanding please.

Best Answer

This is a standard format Intel hex file used by many manufacturers' linkers.

The first character is always ':'

The next two hex digits are the byte count, in two-digit pairs, in the data field of the line. So the first line has two bytes of data, the next eight bytes, and tghe last zero bytes.

The next four hex digits are the address, in bytes. Olin has already mentioned why the starting address of 33 (0x21) is display as 0042.

The next two hex digits are the record type. 02 is an extended address type, allowing addresses to extend beyond the 64K limit of the original format. But the data field following the 02 in the first line is 0000, so there really isn't any extension in this case.

The last two hex digits are the checksum (see the Wikipedia article for the calculation).

In the second line, the 00 record says there will be an address field (e.g. 0042) preceding the record type, and the eight bytes of data following the record type (00,C0,... thru CF).

The last line, with the record type of 01, is an end of record.