Is the amount of flash memory occupied by a program on a chip possible to calculate based on the content and size of the .HEX file? And if not, is there another way?
Does a chip claiming to have 32kB of flash memory have exactly 32kB of availible flash memory?
Example:
Mark has an unhealthy concern for amount of flash memory remaining on his ATMEGA328P microprocessor after he programs it using an assembled .HEX file and avrdude tool provided by Atmel. Therefore he opens the .HEX file using a text editor and counts the bytes:
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9453000C940000E2
:100080008FEF84B987B985B1809585B988B180959E
:1000900088B92FEF83ED90E3215080409040E1F745
:0A00A00000C00000F0CFF894FFCF7D
:00000001FF
His result is 115 bytes in total or 118 including ":". Mark however realises that of these bytes a certain amount is checksums and flags. When Mark runs avrdude in order to flash the hardware with his code the tool tells him that the file contains 170 bytes. This confuses and intimidates him due to total amount of free flash memory on the chip being just 188 times more than what the tool told him about the number of bytes in the file. He breaks down in tears.
To avoid Mark's emotional breakdowns it would be good to be able to estimate the number of bytes in the flash memory occupied by an program stored in the .HEX file.
P.S. Mark is looking to use a much cheaper low - end system in the future and needs to know the amount of memory occupied by his program on such system.
1) generally no. but in the case of intel hex format and motorola srecord a very high percentage of the size of the file is directly related to the flash/rom content. So you cannot accurately to the byte compute, but you can get close.
2) this file format is so simple to parse, takes literally 15 minutes or less from scratch to write a parser, probably less time that it took for you to research on the net and then write this question. Just parse it.
3) if they advertise an amount of flash, that is how much flash it has. Sometimes they will play number games and the one amount on a short feature list includes a bootloader area or other areas, but generally not these days as that will bite them in the end.
4) there are many tools that tell you how much your program is consuming, in the popular toolchains, just a matter of reading the manual, searching the net, etc. Or spending the 45 minutes to find someones elf or srec or ihex parser and trying to figure out how to use it, or the 15 minutes to write your own from scratch for any of these tools, or the 2-3 minutes it takes to learn how to use the existing toolchain tools.