PHY 201 (Blum)1 Stacks Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.

Slides:



Advertisements
Similar presentations
CPU Review and Programming Models CT101 – Computing Systems.
Advertisements

Infix, Postfix and Stacks
1BA3 G Lacey Lecture 51 Evaluating mathematical expressions  How do computers evaluate x + y or any mathematical expression ?  Answer : “Reverse Polish.
TK 2633 Microprocessor & Interfacing
Execution of an instruction
Infix, Postfix, Prefix.
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Memory - Registers Instruction Sets
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Digression: the “Stack” 1 CS502 Spring 2006 Digression: the “Stack” Imagine the following program:– int factorial(int n){ if (n
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
Group 5 Alain J. Percial Paula A. Ortiz Francis X. Ruiz.
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Lecture 18 Last Lecture Today’s Topic Instruction formats
Programming Models CT213 – Computing Systems Organization.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
Machine Instruction Characteristics
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
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.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
Programmer's view on Computer Architecture by Istvan Haller.
Computer Architecture and the Fetch-Execute Cycle
Computer Architecture and the Fetch-Execute Cycle
Microcode Source: Digital Computer Electronics (Malvino and Brown)
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
Chapter 8: The Very Simple Computer
Execution of an instruction
PHY 201 (Blum)1 Microcode Source: Digital Computer Electronics (Malvino and Brown)
1 Purpose of This Chapter In this chapter we introduce a basic computer and show how its operation can be specified with register transfer statements.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
Instructions. Portability In addition to making hardware backward compatible, we have also made software portable. In describing software, “portable”
Processor Architecture
More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t.
COMPUTER ORGANIZATIONS CSNB123 NSMS2013 Ver.1Systems and Networking1.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
CSIT 301 (Blum)1 Instructions at the Lowest Level Some of this material can be found in Chapter 3 of Computer Architecture (Carter)
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Overview of Instruction Set Architectures
Control Unit Lecture 6.
COMPSCI 107 Computer Science Fundamentals
Infix to postfix conversion
The Stack.
William Stallings Computer Organization and Architecture 8th Edition
Architecture Review Instruction Set Architecture
Chapter 10 And, Finally... The Stack
Stacks Chapter 4.
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Overview Introduction General Register Organization Stack Organization
Computer Organization and Design
Instructions at the Lowest Level
Chapter 10 The Stack.
About Instructions Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter PHY 201 (Blum)
The Processor and Machine Language
CSCE Fall 2013 Prof. Jennifer L. Welch.
Chapter 8 Central Processing Unit
Processor Organization and Architecture
CSCE Fall 2012 Prof. Jennifer L. Welch.
ECE 352 Digital System Fundamentals
8051 ASSEMBLY LANGUAGE PROGRAMMING
Some Assembly (Part 2) set.html.
A Top-Level View Of Computer Function And Interconnection
Computer Organization and Assembly Language
Computer Operation 6/22/2019.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
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:

PHY 201 (Blum)1 Stacks Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter

PHY 201 (Blum)2 Ordering of opcodes and operands Postfix: operand(s) then opcode –4 5 + –Works well with stacks Prefix: opcode then operand(s) –+ 4 5 Infix: operand opcode operand –4 + 5

PHY 201 (Blum)3 Precedence (aka Order of Operations) Precedence is the order in which operations occur when an expression contains more than one operation. Operations with higher precedence are performed before operators with lower precedence. –1 + 2 * – (multiplication has higher precedence) –7 - 4 (start on the left when operators have the same precedence) –3

CSIT 301 (Blum)4 Postfix good for Hardware Postfix order is better suited for hardware since one must prepare the inputs (a.k.a. the data, a.k.a. the operands) before operating on them to get an output. Postfix is particularly well suited for architectures that use a stack to perform computations.

CSIT 301 (Blum)5 The stack A stack is a data structure (which may be implemented in hardware or in software) that holds a sequence of data but limits the way in which data is accessed. A stack obeys the Last-In-First-Out (LIFO) protocol, the last item written (pushed) is the first item to be read (popped).

CSIT 301 (Blum)6 Stack is pushed onto the stack 2 is popped off of the stack

CSIT 301 (Blum)7 Stack Pointer: don’t move all the data just change the pointer X X X X X 1 X X X X 2 1 X X X X 2 1 X X X X 3 1 X X X The stack pointer is pointing to the next available location in the stack. When it’s pointing at the 2, the 2 is no longer on the stack.

PHY 201 (Blum)8 Evaluating a postfix expression using a stack (1) Enter the postfix expression and click Step

PHY 201 (Blum)9 Evaluating a postfix expression using a stack (2)

PHY 201 (Blum)10 Evaluating a postfix expression using a stack (3)

PHY 201 (Blum)11 Evaluating a postfix expression using a stack (4)

PHY 201 (Blum)12 Evaluating a postfix expression using a stack (5)

PHY 201 (Blum)13 Evaluating a postfix expression using a stack (6)

PHY 201 (Blum)14 Evaluating a postfix expression using a stack (7)

PHY 201 (Blum)15 Evaluating a postfix expression using a stack (8)

PHY 201 (Blum)16 Evaluating a postfix expression using a stack (9)

PHY 201 (Blum)17 Evaluating a postfix expression using a stack (10)

PHY 201 (Blum)18 Evaluating a postfix expression using a stack (11)

PHY 201 (Blum)19 Evaluating a postfix expression using a stack (12)

PHY 201 (Blum)20 Evaluating a postfix expression using a stack (13)

PHY 201 (Blum)21 Evaluating a postfix expression using a stack (14)

PHY 201 (Blum)22 Evaluating a postfix expression using a stack (15)

PHY 201 (Blum)23 Evaluating a postfix expression using a stack (16)

PHY 201 (Blum)24 Evaluating a postfix expression using a stack (17)

PHY 201 (Blum)25 Evaluating a postfix expression using a stack (18)

PHY 201 (Blum)26 Evaluating a postfix expression using a stack (19)

PHY 201 (Blum)27 Evaluating a postfix expression using a stack (20)

PHY 201 (Blum)28 Evaluating a postfix expression using a stack (21)

PHY 201 (Blum)29 Evaluating a postfix expression using a stack (22)

PHY 201 (Blum)30 Evaluating a postfix expression using a stack (23)

PHY 201 (Blum)31 Evaluating a postfix expression using a stack (24)

PHY 201 (Blum)32 Evaluating a postfix expression using a stack (25)

PHY 201 (Blum)33 Evaluating a postfix expression using a stack (26)

PHY 201 (Blum)34 Evaluating a postfix expression using a stack (27)

PHY 201 (Blum)35 Evaluating a postfix expression using a stack (28)

PHY 201 (Blum)36 Evaluating a postfix expression using a stack (29)

PHY 201 (Blum)37 Evaluating a postfix expression using a stack (30)

PHY 201 (Blum)38 Evaluating a postfix expression using a stack (31)

PHY 201 (Blum)39 Evaluating a postfix expression using a stack (32)

PHY 201 (Blum)40 Evaluating a postfix expression using a stack (33)

PHY 201 (Blum)41 Evaluating a postfix expression using a stack (34)

CSIT 301 (Blum)42 Jump A processor generally assumes that the next statement to be executed is the next line of the code stored in memory. –Recall part of the fetch-execute cycle is to increment the program counter (PC). A jump or goto alters this usual plan. A new value is placed into the program counter.

CSIT 301 (Blum)43 Conditional Jump A conditional jump will change the PC or leave it unchanged based on the state of one of the Flag registers. –The ALU can perform some comparison and place the result in a flag register, then the flag’s value could eventually be fed to the PC load control. So the PC is loaded (changed) or not based on the flag which came from the comparison. Conditional jumping gives the programmer ifs and loops.

CSIT 301 (Blum)44 Calling a subroutine A subroutine call involves a jump. This “passes the control” to the subroutine. But a subroutine call differs from an ordinary jump in that one wants to return. –One reason for having subroutines is to reduce repeated code. The subroutine may be called from any number of locations, so the return address is not known until the program is running.

CSIT 301 (Blum)45 Storing the PC Prior to executing the jump portion of a call, the PC holds the address of the line of code immediately following the call instruction. And this is where one wants to be upon returning from the subroutine. Thus we have to store the value of the program counter (somewhere) and then change the value of the PC (i.e. execute the jump)

CSIT 301 (Blum)46 A subroutine can call another subroutine that can call another subroutine that …. There cannot be a simple register for storing the PC (return address) because a subroutine can call another subroutine requiring two stored values. –In certain early architectures there was just a register for this purpose, but that was too limiting.

CSIT 301 (Blum)47 Calling and Returning Calling: If Main calls RoutineA, we store the MainReturnAddress. Then if RoutineA calls RoutineB, we store RoutineAReturnAddress. Returning: RoutineB returns control to RoutineA so we first need the last return address stored (RoutineAReturnAddress). Then RoutineA returns the control to Main and we need MainReturnAddress. The last return address stored is the first one needed, this is the protocol of a stack. (LIFO)

CSIT 301 (Blum)48 Call is to Push as Return is to Pop A subroutine call thus requires pushing the value of the PC onto a stack (and then changing the value of the PC). A return from a subroutine requires popping the return address from the stack (and then placing that value in the PC).

PHY 201 (Blum)49 References Computer Architecture, Nicholas Carter Computers Systems: Organization and Architecture, John Carpinelli Progs/stack/Polish.html