Beruflich Dokumente
Kultur Dokumente
3 Stack Organization
Stack: A storage device that stores
information in such a manner that the
item stored last is the first item
retrieved.
Initialization
SP ← 0, EMPTY ← 1, FULL
← 0
Push
SP ← SP + 1
M[SP] ← DR
If (SP = 0) then (FULL
← 1) Note that SP becomes 0
after 63
EMPTY ← 0
The following are the micro-
operations associated with the stack
Pop
DR ← M[SP]
SP ← SP - 1
If (SP = 0) then
(EMPTY ← 1)
FULL ← 0
STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
Reverse polish notation :is a postfix
notation (places operators after
operands)
(Example)
Infix notation A+B
Reverse Polish notation AB+ also called
postfix.
STACK OPERATIONS
REVERSE 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 * +
STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
n • Evaluation procedure:
n (Example)
infix 3 * 4 + 5 * 6 = 42
postfix 3 4 * 5 6 * +
n 12 5 6 * +
12 30 +
42
STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
• Reverse Polish notation evaluation with a
stack.
Stack is the most efficient way for evaluating
arithmetic expressions.
stack evaluation:
Get value
If value is data: push data
Else if value is operation:
pop, pop evaluate and push.
STACK OPERATIONS
REVERSE POLISH NOTATION (postfix)
(Example) using stacks
to do this.
3 * 4 + 5 * 6 = 42
=> 3 4 * 5 6 * +
8.4 Instruction Formats
• The most common fields in instruction formats are:
1. Mode field: Specifies the way the effective address is determined
2. Operation code: Specifies the operations to be performed.
3. Address field: Designates a memory address or a processor
register
Instruction: POP X
Evaluate X = ( A + B ) * ( C + D )
PUSH A TOS ← A
PUSH B TOS ← B
ADD TOS ← ( A + B )
PUSH C TOS ← C
PUSH D TOS ← D
ADD TOS ← (C + D)
MUL TOS ← (C + D) ∗ ( A + B)
POP X X ← TOS
LOAD A AC ← M [ A]
ADD B AC ← AC + M [ B ]
STORE T M [T ] ← AC
All operations are done between the AC register and memory operand
MOV R1, A R1 ← M [ A]
MOV R2, B R 2 ← M [ B]
ADD R1, R2 R1 ← R1 + R 2
MOV X, R1 M [ x ] ← R1