IAR; different code debug & release size; queries

Vindhyachal Takniki

Joined Nov 3, 2014
569
1. I have made code in IAR which I have attached.
2. I have made same debug & release optimization setting i.e High, Speed, No size constraint.
Surprisingly code generated in both are different even if optimization settings are same even if there is no additional code in debug or release.
3. Code is just:
Code:
#include "stm8s.h"

int main( void )
{
return 0;
}

4. Size in debug :
read only code memory = 106 bytes
read only data memory = 128 byte
read write data memory = 256 bytes

5. Size in release:
read only code memory = 63 bytes
read only data memory = 128 byte
read write data memory = 256 bytes

Questions:
1. Why different code size?
2. I didn't find any map file generated?
3. Is there not any zero initialized data in memory?
All vars declared go to read write memory?
e.g if I decalre uint8_t var; it goes to read write memory.
Even if I don't assign any value to it.

4. Is flash & ram size are below:

ram size = read write data memory

Attachments

• 206.8 KB Views: 16

ErnieM

Joined Apr 24, 2011
8,089
Attachment cannot be opened.

1. Code size is different to insert whatever steps your debugger needs.

2. Your compiler may need a switch enabled to generate your map.

3. You do not declare any variables. Typically varables are zeroed, but this depends on your compiler.

4. Flash is generally the program memory. Some compilers stick constant data here too. RAM is the variables (and sometimes constants too depending on how they are declared).

tshuck

Joined Oct 18, 2012
3,534
The discrepancy in size is due to the code required to report to the debugger the status of the device and its registers while in debug mode. Release mode removes all those and will typically be smaller as a result.

Zeroing a variable typically requires an actual write operation to clear the register. Some compilers do this, some do it as needed, and still others don't do it, knowing that -1 is the uninitialized value (where applicable).

You're compiler determines where variables are stored. Compilers often have a way to force a value to be stored in a specific memory space, but it is not generally needed. Must often, declaring a variable is using RAM (read+write memory, not to be confused with the program memory [flash] when using a Harvard variant architecture).

Remember, C is not what is executed on your device. It understands ones and zeros only and this high-level language must be compiled down to these ones and zeros. In that process, the compiler attempts to do the actions you've specified in C using the machine code the device understands., sometimes reserving variables in memory for its use.

MrChips

Joined Oct 2, 2009
22,583
To generate a map file:

1. Select the project name in the Workspace tree
3. Project>Build
4. Click on the .map file in the Output tree.