This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Where is the stack?

I have a few questions that may be related.
I'm using a Cygnal C8051F021 which has 4352 bytes of XRAM. I have a c program using the LARGE memory model and am wondering how much stack I am using. I guess I mainly want to know where the stack is being placed
In my .M51 file there is the line:
IDATA 0022H 0001H UNIT ?STACK
What does this mean?
I'm not explicitly including the STARTUP.A51 but in the M51 file I see:
CODE 3416H 008CH UNIT ?C_C51STARTUP
Is this some kind of default that gets put in?
Thanks in advance for any help.

  • In my .M51 file there is the line:
    IDATA 0022H 0001H UNIT ?STACK
    What does this mean?


    This is where the stack starts. On the 8051, the stack must reside in on-chip IDATA memory. The stack grows UP, so the linker locates it after all of your variables. Note that function arguments are NOT placed on the stack. Refer to the following knowledgebase article for more information:

    http://www.keil.com/support/docs/961.htm

    I'm not explicitly including the STARTUP.A51 but in the M51 file I see:
    CODE 3416H 008CH UNIT ?C_C51STARTUP
    Is this some kind of default that gets put in?


    Default startup code is included in the C libraries. If you do not include a project-specific startup file, the default one is brought in from the library. The startup code is REQUIRED for a program to work. The startup contains the reset vector, code that clears on-chip DATA memory (so global variables are set to 0), code that initializes your global variables, code that initializes the stack pointer, and finally a jump to the MAIN C function.

    Jon

    P.S. All of this stuff is covered in the manual.