What is left behind when uploading to Arduino

Hi All,
I am learning so my sketches have a lot of annotation and my variables have long names that make it easier for me to follow my own sketches.
I am wondering what gets transfered to the arduino when uploading from the IDE?
Does all the annotation get left behind and only seen on the PC?
Do long variable names take up arduino memory?

1 Like

The comments do no form part of the uploaded code. How much memory is taken by a variable depends on its data type, not its name

For instance

byte x = 1;

uses just as much memory as

byte start_position_of_player_one_in_the_game = 1;

The compiler turns your sketch into machine instructions that the processor can understand and may also optimise the code for speed or to reduce its size

That's excellent! Programming for 50 years I know how fast I've forgotten details in old codes. Good comments is the recipe to remind You!
You're on a very good track!

2 Likes

If you look at your file size many times it is bigger then the processor. What the compiler does as I understand it is take your code, libraries and other ino files in that folder, combines them then strips off everything that it does not need such as comments etc. It will also substitute numbers etc for your constructs, defines etc, those labels are for the programmer, not the machine. It then converts this to assembler code and then the assembler converts it to machine code which is then located to the correct address etc. That is then placed into a HEX file which is uploaded to the Arduino. This process can be combined differently depending on who is writing it. Because of this you can never get the source code out of the Arduino, it does not exist. It is possible to get the code in HEX code format, convert to binary then run a disassembler to generate assembler source code. It will not have any of your original labels etc. Hopefully this helps.

4 Likes

Better, we say Intel-hex (formatted) file which is an ASCII coded "Transmission File" to avoid confusion with hex-format (compact from of binary-format). The Boot Loader receives the Intel-hex frame (s), extracts the binary/machine codes of the sketch and stores them into the target locations of the Flash Memory using SPM Instruction.

1. Example of Intel-hex Frame (the Tranmission Frame)
:100000000C9434000C9446000C9446000C9446006A
//transmitted as: 0x3A (ASCII code of :, 0x31 ASCII code of 1, ..., 0x36, 0x41)

2. Binary/Machine Codes of the sketch extracted from Step-1 by the Boot Loader:
0C9434000C9446000C9446000C944600
//retrived as: 0x0C, 0x94, ..., 0x46, 0x00)

sidenote: as long as do not turn on debug symbols your variable names, line numbers etc. are not in the uploaded binary. If you turn on "-g", they are and you can use gdb to remotely debug with ease.

Add this to your source file, " Serial.print(BASE_FILE);"it will tell you where the files are located. Just work back and you will find what was not deleted. It is different on different machines depending on OS and install.

The ASCII HEX file was originally called intel Hex Record and shortly Motorola came out with the Motorola S record file. Both are similar and also in non ASCII versions. They were originally a maximum of 64K bytes of memory support, that was later expanded.

The forum mangled your reply

Serial.print(__BASE_FILE__);

is what is needed

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.