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.

Slides:



Advertisements
Similar presentations
Eng. Mohammed Timraz Electronics & Communication Engineer University of Palestine Faculty of Engineering and Urban planning Software Engineering Department.
Advertisements

Major components of CPU
There are two types of addressing schemes:
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title : Overview of Stack.
Operand And Instructions Representation By Dave Maung.
Stacks Chapter 5. Chapter Objectives  To learn about the stack data type and how to use its four methods: push, pop, peek, and empty  To understand.
Instruction Set Architecture & Design
Stacks Chapter 5. Chapter 5: Stacks2 Chapter Objectives To learn about the stack data type and how to use its four methods: push, pop, peek, and empty.
Reverse Polish Expressions Some general observations about what they are and how they relate to infix expressions. These 9 slides provide details about.
Implementation of a Stored Program Computer
The Stack and Queue Types Lecture 10 Hartmut Kaiser
Processor Organization and Architecture Module III.
Lecture 18 Last Lecture Today’s Topic Instruction formats
205 : Computer Organization and Architecture
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Comp 245 Data Structures Stacks. What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO.
Stack Applications.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Lecture 17 Today’s Lecture –Instruction formats Little versus big endian Internal storage in the CPU: stacks vs. registers Number of operands and instruction.
Chapter 10 And, Finally... The Stack. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Stacks A LIFO.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Instruction Set Architecture
Chap. 8 Central Processing Unit
L/O/G/O The Instruction Set Chapter 9 CS.216 Computer Architecture and Organization.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
December 8, 2003Other ISA's1 Other ISAs Next, we discuss some alternative instruction set designs. – Different ways of specifying memory addresses – Different.
Chap. 9 Instruction Set Architecture. Computer Architecture Concepts Instruction format –Opcode field Specify the operation to be performed –Address field.
Chapter 5 A Closer Look at Instruction Set Architectures.
Chapter 5 A Closer Look at Instruction Set Architectures.
COMPUTER ARCHITECURE INSTRUCTION SET ARCHITECTURE.
M. Mateen Yaqoob The University of Lahore Spring 2014.
Operand Addressing And Instruction Representation Cs355-Chapter 6.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Wednesday, March 2 Homework #2 is posted Homework #2 is posted Due Friday, March 4 (BOC) Due Friday, March 4 (BOC) Program #5 is posted Program #5 is posted.
What is a program? A sequence of steps
Operand Addressing And Instruction Representation Tutorial 3.
CPU performs the bulk of data processing operations CPU performs the bulk of data processing operations The CPU is made up of three parts. They are Control.
CH-8 CENTRAL PROCESSING UNIT -BY ESHA S. SHAH 1.  CENTRAL PROCESSING UNIT Introduction General Register Organization Stack Organization Instruction Formats.
PHY 201 (Blum)1 Stacks Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.
Computer Organization 1
Instruction Formats Competency: C5 Lecture no. 24.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
1 Classification of instructions 4-address instructions 3-address instructions 2-address instructions 1-address instructions 0-address instructions.
Logic and Computer Design Fundamentals
Chapter 2. Machine Instructions and Programs
Overview of Instruction Set Architectures
COMPSCI 107 Computer Science Fundamentals
Architecture Review Instruction Set Architecture
A Closer Look at Instruction Set Architectures: Expanding Opcodes
Stacks Chapter 4.
Stack application: postponing data usage
PART II STACK APPLICATIONS
Overview Introduction General Register Organization Stack Organization
Computer Organization and Design
Computer Organization and Assembly Language (COAL)
Chapter 10 The Stack.
CENTRAL PROCESSING UNIT
Chapter 8 Central Processing Unit
Processor Organization and Architecture
CENTRAL PROCESSING UNIT
ECEG-3202 Computer Architecture and Organization
Classification of instructions
A Closer Look at Instruction Set Architectures Chapter 5
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
Other ISAs Next, we’ll first we look at a longer example program, starting with some C code and translating it into our assembly language. Then we discuss.
ECEG-3202 Computer Architecture and Organization
Addressing mode summary
Central Processing Unit.
Stacks A stack is an ordered set of elements, for which only the last element placed into the stack is accessible. The stack data type is also known as.
Presentation transcript:

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.

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.

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

REGISTER STACK • 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. 4

The following are the micro-operations associated with the stack 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 5

DR ¬ M[SP] SP ¬ SP - 1 If (SP = 0) then (EMPTY ¬ 1) FULL ¬ 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 6

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) • 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

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: Mode field: Specifies the way the effective address is determined Operation code: Specifies the operations to be performed. Address field: Designates a memory address or a processor register Mode Opcode Address 12

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. •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.

Zero address instructions 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 X Evaluate X = ( A + B ) * ( C + D ) PUSH, and POP instructions need an address field to specify the operand

Zero address instructions PUSH A PUSH B ADD PUSH C PUSH D MUL POP X Advantages: No memory addresses needed during the operation. Disadvantages: results in longer program codes.

One address instructions One address can be a register name or memory address. SINGLE ACCUMULATOR ORGANIZATION Since the accumulator always provides one operands, only one memory address needs to be specified. Instruction: ADD X Microoperation: AC ¬ AC + M[X]

One address instructions LOAD A ADD B STORE T  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.

Two address instructions • 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, R2 Microoperation: R1  R1 + R2

Two address instructions 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 programs Disadvantages: more bits are needed to specify two addresses.

Three address organization GENERAL REGISTER ORGANIZATION • Three address instructions: Memory addresses for the two operands and one destination need to be specified. Instruction: ADD R1, R2, R3 Microoperation: R1  R2 + R3 Advantages: results in writing short programs Disadvantages: more bits are needed to specify three addresses. ADD R1, R2, R3

EXAMPLE: Show how can the following operation be performed using: a- three address instruction b- two address instruction c- one address instruction d- zero address instruction X = (A + B) * (C + D) 21

a-Three-address instructions (general register organization) 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 22

b-Two-address instructions (general register organization) MOV R1, A R1  M[A] ADD R1, B R1  R1 + M[B] MOV R2, C R2  M[C] ADD R2, D R2  R2 + M[D] MOV X, R2 M[X] R2 MUL X, R1 M[X]  R1 * M[X] 23

c- One-address instructions LOAD A AC M[A] ADD B AC  AC + M[B] STORE T M[T ] AC LOAD C AC  M[C] ADD D AC  AC + M[D] MUL T AC  AC * M[T ] STORE X M[X]  AC Store 24

d- Zero-address instructions (stack organization) 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 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 25