C251 User's Guide

Hardware Stack

The 251 architecture is designed to allow structured languages like C. Therefore, the MCU instruction set supports stack-relative variables with the MOV @DR60 instruction. The 251 hardware stack direction is from the bottom upwards. The hardware stack pointer is initialized in the file START251.A51 which executes before the C main function is called and reserves the space for the hardware stack.

The 251 hardware stack holds parameters and automatic variables for reentrant code. The stack layout during the execution of a reentrant function is show in the following example. Refer to Reentrant Functions for more information.

C Function
pragma functions (reentrant)

void func (long a, long b, int c)  {
  char  x1, x2;
  int   y;
  float z;

  :
  :
}
User Stack Layout after Execution of the Epilog of func:
Stack ItemStack Location
int c@DR60-19
Ret Addr.@DR60-17
long b@DR60-15
long a@dr60-11
float z@DR60-7
int y@DR60-3
char x2@DR60-1
char x1@DR60

Note

  • The above stack layout is generated if C251 works without optimization (C251 control directive OPTIMIZE (0) is in effect). In regular C programs the C251 optimizer allocates parts of the stack variables to MCU registers.
  • The shown code is called with standard LCALL instructions. If you translate with the ROM (HUGE) directive the space required for the return address is 3 bytes.
  • The parameters a and b are passed in registers and therefore located on the stack after the return address. The parameter c cannot be passed anymore in registers and is located before the return address on stack.