W07_14_Stacks - 14a Stacks CSC 230 Department of Computer...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
14a Stacks CSC 230 Department of Computer Science University of Victoria
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Remember Stacks? ± List of contiguous data elements with register Stack pointer 0 access only from one end IFO ata 17 SP Current top element 39 28 - ± LIFO data structure: Last In First Out ottom Stack 739 Î PUSH: place a new element on the top of the tack BOTTOM element Bottom 43 stack Î POP: remove element from the top of the stack A stack of words in memory
Background image of page 2
Stacks and Memory register Stack pointer 17 SP Current top element 39 28 - C0124 C0128 012C ottom Stack 739 ± Easiest and most common: C012C BOTTOM element Bottom 43 Stack grows from bottom to top us top C023A thus top element has “lower” address than bottom A stack of words in memory
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Effect of stack operations: PUSH P SP 19 SP 17 739 28 - 17 739 28 - Stack Stack NEWITEM 19 43 19 43 (a) Before push of NEWITEM (b) After push from NEWITEM
Background image of page 4
Effect of stack operations: POP P 8 - SP 17 739 28 - 17 739 SP 28 Stack ITEM 43 43 ITEM 28 - (a) Before pop into ITEM (b) After pop into ITEM
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
In general for a PUSH on STACK 1. SP contains the address of the top of the stack 2. Decrement SP to point to the slot towards lower memory . opy to the stack in the location pointed to by the updated SP 3. Copy to the stack in the location pointed to by the updated SP C011C Subtract #4 from SP tore NEWITEM [SP] SP 17 28 - C0120 C0124 C0128 012C Store NEWITEM, [SP] 739 C012C Assume R2=NEWITEM SUB SP,SP,#4 STR R2, [SP] 43 C023A Better: TR 2 [SP # ]! NEWITEM 19 STR R2, [SP,#-4]!
Background image of page 6
In general for a PUSH on STACK 1. SP contains the address of the top of the stack 2. Decrement SP to point to the slot towards lower memory . opy to the stack in the location pointed to by the updated SP 3. Copy to the stack in the location pointed to by the updated SP C011C Subtract #4 from SP tore NEWITEM [SP] 17 28 - SP C0120 C0124 C0128 012C Store NEWITEM, [SP] 739 C012C Assume R2=NEWITEM SUB SP,SP,#4 STR R2, [SP] 43 C023A Better: TR 2 [SP # ]! NEWITEM 19 STR R2, [SP,#-4]! 19
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
In general for a POP from STACK 1. SP contains the address of the top of the stack 2. Copy from the location pointed to by SP into a register 3. Increment SP to point to the slot towards higher memory C011C C0120 Load NEWITEM, [SP] dd #4 to SP 28 - SP C0124 C0128 C012C Add #4 to SP 17 739 C023A Assume NEWITEM Î R2 LDR R2, [SP] ADD SP,SP,#4 Better: DR 2 [SP] #4 43 ITEM 28 - LDR R2, [SP],#4
Background image of page 8
General (visual) summary 1 nused Lower emory nused Stack ointer Lower New Unused Unused Unused Memory Address Stack Unused Unused Pointer SP Memory Address Data1 Data3 Data2 Pointer SP Higher Data3 Data2 w ta1 PUSH Data1 g Memory Address Data1 Ne Da t Higher Memory Address tack pointer after a PUSH Stack pointer after a PUSH
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
General (visual) summary 2 POP Unused New New Data2 Unused New Stack Pointer P Lower Memory ddress New Data1 PUSH Data2 a2 New Data1 ata3 Data2 SP Stack
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course CSC 230 taught by Professor Jasond.corless during the Summer '11 term at University of Victoria.

Page1 / 28

W07_14_Stacks - 14a Stacks CSC 230 Department of Computer...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online