# 8.3 Stack Organization - PowerPoint PPT Presentation

PPT – 8.3 Stack Organization PowerPoint presentation | free to view - id: 5e8c4e-MDBiY

The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
Title:

## 8.3 Stack Organization

Description:

### Title: PowerPoint Presentation Author: Bernard Chen Last modified by: Bernard Chen Created Date: 1/21/2009 1:35:13 AM Document presentation format – PowerPoint PPT presentation

Number of Views:2249
Avg rating:5.0/5.0
Slides: 26
Provided by: bernar5
Category:
Tags:
Transcript and Presenter's Notes

Title: 8.3 Stack Organization

1
8.3 Stack Organization
• Stack A storage device that stores information
in such a manner that the item stored last is the
first item retrieved.
• Also called last-in first-out (LIFO) list. Useful
for compound arithmetic operations and nested
subroutine calls.

2
8.3 Stack Organization
• Stack pointer (SP) A register that holds the
address of the top item in the stack. SP always
points at the top item in the stack
• Push Operation to insert an item into the
stack. Pop Operation to retrieve an item from
the stack.

3
REGISTER STACK
• A stack can be organized as a collection of a
finite number of registers.

4
In a 64-word stack, the stack pointer contains
6 bits. The one-bit register FULL is set to 1
when the stack is full EMPTY register is 1 when
the stack is empty. The data register DR holds
the data to be written into or read from the
stack.
REGISTER STACK
5
The following are the micro-operations associated
with the stack
InitializationSP 0, EMPTY 1, FULL
0Push SP SP 1MSP DRIf (SP 0) then
(FULL 1) Note that SP becomes 0 after 63EMPTY
0
6
DR MSPSP SP - 1If (SP 0) then (EMPTY
1)FULL 0
The following are the micro-operations associated
with the stack
Pop
7
STACK OPERATIONSREVERSE POLISH NOTATION (postfix)
• Reverse polish notation is a postfix notation
(places operators after operands)
• (Example) Infix notation A BReverse Polish
notation AB also called postfix.

8
STACK OPERATIONSREVERSE POLISH NOTATION (postfix)
• A stack organization is very effective for
evaluating arithmetic expressions
• A B C D ? (AB )(CD ) ? AB CD
• ( 3 4 ) ( 5 6 ) ? 34 56

9
STACK OPERATIONSREVERSE POLISH NOTATION (postfix)
• Evaluation procedure
• 1. Scan the expression from left to right.2.
When an operator is reached, perform the
operation with the two operands found on the left
side of the operator.3. Replace the two operands
and the operator by the result obtained from the
operation.
• (Example) infix 3 4 5 6 42 postfix 3 4
5 6
• 12 5 6 12 30 42

10
STACK OPERATIONSREVERSE POLISH NOTATION (postfix)
• Reverse Polish notation evaluation with a
stack. Stack is the most efficient way for
evaluating arithmetic expressions.

stack evaluationGet valueIf value is data
push dataElse if value is operation pop, pop
evaluate and push.
11
STACK OPERATIONSREVERSE POLISH NOTATION (postfix)
• (Example) using stacks to do this. 3 4 5
6 42
• gt 3 4 5 6

12
8.4 Instruction Formats
• The most common fields in instruction formats
are
• Mode field Specifies the way the effective
• Operation code Specifies the operations to be
performed.
processor register

Mode
Opcode
13
8.4 Instruction Formats
• Zero address instruction Stack is used.
Arithmetic operation pops two operands from the
stack and pushes the result.
• One address instructions AC and memory. Since
the accumulator always provides one operand, only
one memory address needs to be specified.
or two memory locations are specified, one for
the final result.
registers or memory locations are specified, one
for the final result. It is also called general

14
Instruction ADD Push and pop operations need to
specify one address involved in data transfer.
Stack-organized computer does not use an address
field for the instructions ADD, and MUL
Instruction POP XEvaluate X ( A B ) ( C
D )
PUSH, and POP instructions need an address field
to specify the operand
15
PUSH A PUSH B ADD PUSH C PUSH D ADD MUL POP X
longer program codes.
16
• One address can be a register name or memory
• SINGLE ACCUMULATOR ORGANIZATION
• Since the accumulator always provides one
operands, only one memory address needs to be
AC MX

17
All operations are done between the AC register
and memory operand
Advantages fewer bits are needed to specify
long programs.
18
• Assumes that the destination address is the
same as that of the first operand. Can be a
memory address or a register name.
• Instruction ADD R1, R2Microoperation R1 ? R1
R2

19
MOV R1, A MOV R2, B ADD R1, R2 MOV X, R1
most common in commercial computers Each address
fields specify either a processor register or a
memory operand
Advantages results in writing medium size
programsDisadvantages more bits are needed to
20
• GENERAL REGISTER ORGANIZATION
for the two operands and one destination need to
R3Microoperation R1 ? R2 R3
• Advantages results in writing short
programsDisadvantages more bits are needed to

21
EXAMPLE Show how can the following operation be
B) (C D)
22
organization)
• R1 ? MA MB
• R2 ? MC MD
• MUL X, R1, R2
• MX ? R1 R2

23
organization)
• MOV R1, A
• R1 ? MA
• R1 ? R1 MB
• MOV R2, C
• R2 ? MC
• R2 ? R2 MD
• MOV X, R2
• MX? R2
• MUL X, R1
• MX ? R1 MX

24
• AC? MA
• AC ? AC MB
• STORE T
• MT ? AC
• AC ? MC
• AC ? AC MD
• MUL T
• AC ? AC MT
• STORE X
• MX ? AC Store

25
• Push value
• Else If operator is encountered Pop, pop,
operation, push
• Pop operand pop another operand then perform an
operation and push the result back into the
stack.
• PUSH A TOS ? A Push
• PUSH B TOS ? B