Keil Logo

C51: Locating the Stack after IDATA Variables

Information in this article applies to:

  • C51 Version 5.50a and later


I'm using some idata variables in my program. I want to make sure that the stack doesn't overwrite them. What do I need to do?


The following example program declares variables as you describe:

int idata var1;
int idata var2;
int idata var3;

void main (void)

When compiled and linked, the following Link Map is generated in the MAP file output by the linker.


* * * * * * *   D A T A   M E M O R Y   * * * * * * *
REG     0000H     0008H     ABSOLUTE     "REG BANK 0"
IDATA   0008H     0006H     UNIT         ?ID?MAIN
IDATA   000EH     0001H     UNIT         ?STACK

* * * * * * *   C O D E   M E M O R Y   * * * * * * *
CODE    0000H     0003H     ABSOLUTE
CODE    0003H     000CH     UNIT         ?C_C51STARTUP
CODE    000FH     0001H     UNIT         ?PR?MAIN?MAIN

Note that the idata variables declared come before the stack. The stack on the 8051 grows up. Therefore, there is nothing you must do to avoid overwriting your idata variables.


Last Reviewed: Thursday, February 25, 2021

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.