Keil Logo

Parameters and the Stack

The stack pointer on the classic 8051 accesses internal data memory only. The Cx51 Compiler locates the stack area immediately following all variables in the internal data memory. The stack pointer accesses internal memory indirectly and can use all of the internal data memory up to the 0xFF limit.

The total stack space of the classic 8051 is limited to 256 bytes. Rather than consume stack space with function parameters or arguments, the Cx51 Compiler assigns a fixed memory location for each function parameter. When a function is called, the caller must copy the arguments into the assigned memory locations before transferring control to the desired function. The function then extracts its parameters, as needed, from these fixed memory locations. Only the return address is stored on the stack during this process. Interrupt functions require more stack space because they must switch register banks and save the values of a few registers on the stack.

By default, the Cx51 Compiler passes up to three function arguments in registers. This enhances speed performance. For more information, refer to Parameters and Registers.

Note

  • The Cx51 Compiler uses extended stack areas that are available in some enhanced 8051 variants. In this way the stack space can be increased to several Kilobytes.
  • Some 8051 derivatives provide only 64 bytes of on-chip data memory but most devices have 256 bytes. Take this into consideration when determining which memory model to use, because the amount of on-chip data and idata memory used directly affects the amount of stack space.
  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.