8.3 Stack Organization. Stac k: 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) lis t. Useful for compound arithmetic operations and nested subroutine calls. 8.3 Stack Organization.
• A stack can be organized as a collection of a finite number of registers.
• 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.
InitializationSP ¬ 0, EMPTY ¬ 1, FULL ¬ 0Push
SP ¬ SP + 1M[SP] ¬ DRIf (SP = 0) then (FULL ¬ 1) Note that SP becomes 0 after 63EMPTY ¬ 0
The following are the micro-operations associated with the stack
stack evaluation:Get valueIf value is data: push dataElse if value is operation: pop, pop evaluate and push.
=> 3 4 * 5 6 * +
• 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.
•Two address instructions: Two address registers or two memory locations are specified, one for the final result.
•Three address instructions: Three address registers or memory locations are specified, one for the final result. It is also called general address organization.
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
Advantages: No memory addresses needed during the operation.Disadvantages: results in longer program codes.
All operations are done between the AC register and memory operand
Advantages: fewer bits are needed to specify the address.Disadvantages: results in writing long programs.
MOV R1, A
MOV R2, B
ADD R1, R2
MOV X, R1
Advantages: results in writing medium size programsDisadvantages: more bits are needed to specify two addresses.
• Three address instructions: Memory addresses for the two operands and one destination need to be specified.Instruction: ADD R1, R2, R3Microoperation: R1 R2 + R3
ADD R1, R2, R3
EXAMPLE: Show how can the following operation be performed using:a- three address instructionb- two address instructionc- one address instructiond- zero address instructionX = (A + B) * (C + D)
ADD R1, A, B
R1 M[A] + M[B]
ADD R2, C, D
R2 M[C] + M[D]
MUL X, R1, R2
M[X] R1 * R2
MOV R1, A
ADD R1, B
R1 R1 + M[B]
MOV R2, C
ADD R2, D
R2 R2 + M[D]
MOV X, R2
MUL X, R1
M[X] R1 * M[X]
AC AC + M[B]
M[T ] AC
AC AC + M[D]
AC AC * M[T ]
M[X] AC Store
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
ADD TOS (A+B)
PUSH C TOS C
PUSH D TOS D
ADD TOS (C+D)
MUL TOS (C+D)*(A+B)
POP X M[X] TOS
(*TOS stands for top of stack).
Pop, pop, operation, push