2
\$\begingroup\$

When I download a .hex file using avrdude, I'm seeing a difference between the input and output size. For example, the size of the .hex file is 856 bytes, and what I see in the message is '... avrdude: 298 bytes of flash written ...'

I'm curious as to where the difference is coming from (the .hex file is larger). And would the answer to what is the machine code size (for the corresponding source code .c file), be 298 bytes?

\$\endgroup\$
3
\$\begingroup\$

As the name implies, a hex file contains its data encoded in hexadecimal. Specifically, in intel hex format. If you open the file in a text editor, you'll see it's a series of lines, each starting with a colon, some header data, and a fixed number of hex digits.

Hexadecimal requires two characters to store one byte, so that doubles your filesize right away. Add to that the overhead for the format (specifying addresses to write to, lengths, checksums etc) and you arrive at the final file size.

If AVRDude is reporting 298 bytes written, that is indeed the compiled size of your program.

\$\endgroup\$
1
\$\begingroup\$

To expand upon @Nick's answer, here are some related questions.

Number of bytes and file size(HEX)

Will my HEX file fit in my microcontroller?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.