9. Addressing the STACK

To form a stack, some memory is set aside especially for it by the currently running program. The stack is often a 'dynamic' structure in that it can grow and shrink according to how much data is contains.

Advantage of a stack: The dynamic nature of the stack makes it a very efficient structure because it only uses as much memory as it needs and no more.

In order to locate the last item in the stack, a special pointer is used, called the 'stack pointer'.

The stack pointer

The currently running software maintains the stack pointer. As items are POPed off the stack, the stack pointer is decremented. As items are PUSHed on to the stack, the stack pointer is incremented.

Because the stack pointer is such a basic requirement in computing, the CPU normally contains a dedicated stack pointer register for the programmer to use.

 

 

 

Copyright © www.teach-ict.com