IAR; different code debug & release size; queries

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, Dec 8, 2014.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    349
    6
    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 (Text):
    1.  
    2. #include "stm8s.h"
    3.  
    4. int main( void )
    5. {
    6.   return 0;
    7. }
    8.  
    9.  

    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:

    flash size = read only code memory+ read only data memory+read write data memory
    ram size = read write data memory
     
    • test.zip
      File size:
      206.8 KB
      Views:
      16
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    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).
     
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    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.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,363
    To generate a map file:

    1. Select the project name in the Workspace tree
    2. Select Project>Options...>Linker>List>Generate linker listing>OK
    3. Project>Build
    4. Click on the .map file in the Output tree.
     
Loading...