The Techel
The Techel

Reputation: 873

What is a compiled stack?

I came across said terminology and already picked up that it's somehow used on microcontrollers, but have not found any explanation. What is a compiled stack, what is it used for and why?

Upvotes: 1

Views: 804

Answers (1)

Pibben
Pibben

Reputation: 2025

Compiled stack is a technology used in the PIC range of Microcontrollers.

From MPLAB XC8 C Compiler User's Guide:

A compiled stack is a static allocation of memory for stack-based objects that can be built up in multiple data banks. See Section 5.5.2.2.1 “Compiled Stack Operation” for information about how objects are allocated to this stack. Objects in the stack are in fixed locations and can be accessed using an identifier (hence it is a static allocation). Thus, there is no stack pointer. The size of the compiled stack is known at compile time, and so available space can be confirmed by the compiler. The compiled stack is allo-cated to psects that use the basename cstack; for example, cstackCOMMON, cstackBANK0. See Section 5.15.2 “Compiler-Generated Psects” for more information on the naming convention for compiler-generated psects.

By contrast, the software stack has a size that is dynamic and varies as the program is executed. The maximum size of the stack is not exactly known at compile time and the compiler typically reserves as much space as possible for the stack to grow during pro-gram execution. The stack is always allocated a single memory range, which may cross bank boundaries, but within this range it may be segregated into one area for main-line code and an area for each interrupt routine, if required. A stack pointer is used to indicate the current position in the stack. This pointer is permanently allocated to FSR1.

Upvotes: 2

Related Questions