Home > Electronic Tutorials > Microprocessor Systems Tutorial > The Stack Tutorial

Microprocessor Systems - Electronic Tutorials

The Stack Tutorial

Stack

The stack is a temporary store for data. The CPU may PUSH important data onto the stack, while it is processing other data. When it finishes that task, it PULLS the saved data off the stack. Its like a pile of plates. The bottom plate is the first bit of data that was pushed onto the stack. The top plate is the last data to be pushed. The top plate is pulled first and the bottom plate is the last data to be pulled. It is a LAST IN, FIRST OUT stack.

In the diagrams, X is the first to be pushed, then Y and lastly A.

The CPU goes away to process other data. Upon completion of that task it returns to pull the saved data.

First A is pulled, then Y and lastly X.

The instruction for pushing data is PHA. Only data in the accumulator can be pushed onto the stack. Other data can be pushed if it is transferred to the accumulator first. The instruction for pulling data from the stack is PLA. Data on the stack is transferred to the accumulator.

The 6502 stack consists of 256 bytes and occupies page 1, addresses 256 to 511.

Note: To report broken links or to submit your projects please send email to Webmaster

Discover

     more......