Memory Stack
Memory Stack
Program 1000
PC
(instructions)
AR
Data 2000
(operands)
stack 3000
3997
SP 3998
3999
4000
4001
DR
Example :
The items in the stack communicate with a data register. A new
item is inserted with the push operation as follows:
PUSH:
SP <-SP – 1
M[SP] <- DR
The stack pointer is decremented so that it points at the address
of the next word. A memory write operation inserts the word
from DR into the top of the stack. A new item is deleted with a
pop operation as follows:
POP:
DR <- M[SP]
SP <- SP + 1
INFIX TO POSTFIX
5 c - ab-c
6 - ab-c-
A+B*(C+D)/F+D*E
SYMBOL SCANNED STACK POSTFIX DESCRIPTION
EXPRESSION
1 A A START
2 + + A
3 B + AB
4 * +* AB
5 ( +*( AB
6 C +*( ABC
7 + +*(+ ABC
8 D +*(+ ABCD
9 ) +*(+) ABCD+
10 / +*/ ABCD+* No two operators of
same priority are
stay together
11 F +/ ABCD+*F
12 + +/+ ABCD+*F/+ / has highest priority
than +
13 D + ABCD+*F/+D
14 * + * ABCD+F/+D
15 E +* ABCD+F/+DE
16 + * ABCD+F/+DE*
ABCD+F/+DE*+