Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into.

Similar presentations


Presentation on theme: "1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into."— Presentation transcript:

1 1 Stack Advanced Programming

2 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into the stack: push Getting data from the stack: pull The bottom of the stack is fixed, but the top changes. The size of the stack is dynamic (it changes over time). Since the content of the data in the stack change often, it makes sense to locate it in RAM Usually, the SP is initialized with the highest address in RAM memory.

3 3 The Stack The CPU uses a special 16-bit register called the Stack Pointer (SP) to keep track of the top of the stack (TOS). The SP always points to the address immediately preceding the top of the stack As data is pushed (stored) onto the stack, the stack grows toward lower memory addresses. When data is pulled (removed ) off the stack, the stack shrinks back toward higher memory addresses. In reality, data is never removed from the stack. The hardware simply adjust the SP to point to the new top of the stack. If the stack grows again, the old data is overwritten.

4 4 The Stack

5 5 Using the Stack The instruction LDS Loads the Stack Pointer with an initial value – usually the highest available RAM address. Push instructions: PSHA, PSHB, PSHX, PSHY Pull instructions: PULA, PULB, PULX, PULY

6 6 Push and Pull Examples

7 7 Other instructions affecting the stack DESDecrement Stack Pointer INS Increment Stack Pointer TSX, TSY Transfer Stack Pointer to IX or IY TXS, TYSTransfer IX or IY to Stack Pointer JSRJump to subroutine RTSReturn from subroutine BSRBranch to subroutine RTIReturn from interrupt SWISoftware interrupt WAIWait for interrupt In addition Resets and Interrupts operations also modify the stack

8 8 Interrupt Stacking Order


Download ppt "1 Stack Advanced Programming. 2 The Stack It is a special area of memory used as temporary storage A stack is a LIFO data structure Putting data into."

Similar presentations


Ads by Google