2.2.3 Creating a Stack

The stack is the section of memory used for pushing or popping registers and storing the return address when a subroutine is called. The stack often holds temporary and local variables.

If your main module is written in a high-level language, that language handles the details of creating a stack. Use the .STACK directive only when you write a main module in assembly language.

The .STACK directive creates a stack segment. By default, the assembler allocates 1K of memory for the stack. This size is sufficient for most small programs.

To create a stack of a size other than the default size, give .STACK a single numeric argument indicating stack size in bytes:

.STACK 2048 ; Use 2K stack

For a description of how stack memory is used with procedure calls and local variables, see Chapter 7, “Controlling Program Flow.”