Problem with Scanning an Infix Expression

Size: px
Start display at page:

Download "Problem with Scanning an Infix Expression"

Transcription

1 Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix form. There are two other forms, prefix and postfix, which are occasionally used in software. Infix form has the operator in between two operands, as in X + Y. It is what we are used to, but it is hard for computers to process. The two other forms are prefix and postfix. I give the LISP variant of prefix. Prefix: (+ ( X Y) ( W U) ) Postfix: XY WU + Implicit in each of these examples is the assumption that single letter variables are used. Each of the prefix and postfix is easier for a computer to interpret than is infix. The assumption is that the expression is scanned either left to right or right to left. Here, we arbitrarily scan left to right. We return to this expression, but first consider a much simpler expression.

2 Problem with Scanning an Infix Expression Suppose that we have a five symbol expression. We are scanning left to right. We assume: all variables are single alphabetic characters Each alphabetic characters is taken singly and represents a variable At the beginning we have five unknown symbols: We read the first character and find it to be a variable: We read the next character and find it to be an operator: Something is being added. X X + We read the next character and find it to be a variable: X + Y. Can we do the addition now? It depends on what the next character is. There are two basic possibilities: X + Y + Z X + Y Z In the first option, we can do the addition immediately, forming (X + Y) to which Z is later added. In the second option, we must wait and first do the multiplication to get (Y Z) to which X is added.

3 Scanning a Postfix Expression With the same assumptions, we scan a five symbol postfix expression. At the beginning we have five unknown symbols: We read the first character and find it to be a variable: Y We read the next character and find it also to be a variable: Y Z At this point we need an operator. We read the next character and find it to be an operator: Because this is postfix, the evaluator can immediately form the product term (Y Z) We read the next character and find it to be a variable: At this point, we need another operator. We have two operands: (Y Z) and X. Y Z Y Z X We read the last character and find it to be an operator: Y Z X + We do the addition and have the term (Y Z) + X.

4 The Stack Data Type Stacks are LIFO (Last In, First Out) data structures. Stacks are the data structure most naturally fit to evaluate expressions in postfix notation. The stack is best viewed as an abstract data type with specific methods, each of which has a well defined semantic (we can say exactly what it does). We can also consider the stack as having a top. Items are added to the stack top and then removed from the stack top. The position of the stack top is indicated by a stack pointer (SP). More on this later; it has two different definitions, each of which is valid. The stack data type has three necessary methods, and two optional methods. The mandatory methods are Push, Pop, and IsEmpty. The standard optional methods are Top, and IsFull. Note: When studying computer networks, we speak of a protocol stack, which has nothing to do with the ADT (Abstract Data Type) stack that we study today. We shall discuss the TCP/IP protocol stack later in this course.

5 Pushing Items onto the Stack Consider the sequence: Push (X), Push (Y), and Push (Z). This sequence adds three items to the stack, in the specified order. Push X Push Y Push Z After the third operation, Z is at the top of the stack and is the first to be removed when a Pop operation is performed. The SP (Stack Pointer) is a data item internal to the stack that indicates the location of the top of the stack. It is never made public by any proper stack implementation.

6 The Stack Pointer (SP) The Stack Pointer is that data item used to indicate the location of the stack top. There are two possible interpretations of the SP. While each is completely valid, the two are incompatible. A given implementation can use only one of these. 1. The SP indicates where the next item is to be placed. 2. The SP indicates where the last item was placed. Here we illustrate the operations with Push (X) followed by Push (Y). Next Item Last Item

7 Popping Items from the Stack The Pop operation removes the last item placed onto the stack and places its value into the named variable. Suppose that the three previous operations were Push (X), Push (Y), and Push (Z). The Pop operations are now performed. Pop (W) W gets the value of Z, the last onto the stack. The top of the stack changes. Pop (W) W now gets the value of Y. Pop (W) W now gets the value of X.

8 Other Stack Operations: IsEmpty, Top, and IsFull It is usually important to discover when the last item has been popped from the stack. The stack class can either raise an exception; provide a method to determine if the stack is empty, or both. The standard Boolean function IsEmpty returns TRUE when the stack is empty. Consider the following pseudo code. Loop Until IsEmpty (S) S.Pop (X) // Get top into X Process (X) // Process the value End Loop The optional method Top returns the value at the top of the stack without removing it from the stack. This can be implemented using only Push and Pop. Top (W) Pop (W) Push (W) Place the value at top of the stack into W, but leave it on the stack. Remove the value at top of stack and place into W Place that value back onto the stack. The optional Boolean function IsFull returns TRUE when the stack has been filled completely and cannot accept another item. This occurs when memory is full.

9 Evaluation of the Postfix Expression Y Z X + This is also called RPN for Reverse Polish Notation. Rules: 1. Scan left to right. 2. Upon reading a variable, push it onto the stack. 3. Upon reading a dyadic operator, pop two variables from the stack, perform the operation, and push the result. We read the first character and find it to be a variable: Y We read the next character and find it also to be a variable: Y Z We read the next character and find it to be an operator: Y Z

10 Evaluation of the Postfix Expression Y Z X + Continues We read the next character and find it to be a variable: Y Z X We read the last character and find it to be an operator: Y Z X + After this, the stack will be popped and the value placed into some variable. This example just looked at the expression, without considering the assignment.

11 Stack Based (Zero Operand) Machine Evaluate the expression Z = (X Y) + (W U) which must be evaluated in its postfix (RPN) version: XY WU + Push Push Mult Push Push Mult Add Pop X Y W U Z X X Y X Y X Y W X Y W U X Y W U X Y +W U

12 More Explicit Evaluation: W = Y Z It might be good at this point to make explicit a point that many consider obvious. Suppose that before the evaluation above, W = 0, Y = 10, and Z = 15. The push pop code to execute this instruction will go as follows: PUSH Y // Value of Y is placed on the stack. PUSH Z MULT // Value of Z is placed onto the stack. // Pop the top two values, multiply them // and push the result onto the stack. POP W // Pop the value at stack top and place into W. At the start, here is what we have.

13 PUSH Y More Explicit Evaluation: Part 2 // Value of Y is placed on the stack. PUSH Z // Value of Z is placed onto the stack.

14 MULT More Explicit Evaluation: Part 3 // Pop the top two values, multiply them // and push the result onto the stack. POP W // Pop the value at stack top and place into W.

15 Practical Evaluation of Postfix Operators Here are some steps for manual evaluation. 1. Scan the postfix expression left to right. Find the first operator. 2. Determine how many operands that operator requires. Call it N. Select the previous N operands, apply to the operator. 3. Remove the operator and its operands from the expression. Replace these with the operands results. 4. Repeat Here is an example, using single digit numbers to start with * (6 5 +) 4 2 * (11) 4 2 * (11) (4 2 ) * (11) (2) * 22

16 Practical Evaluation of Prefix Operators Note: We assume Lisp notation, with full use of parentheses. 1. Scan the expression left to right. If the expression does not contain another parenthesized expression, evaluate it. Otherwise, attempt to evaluate its subexpression. Formally, this is viewed as a tree traversal. 2. Keep moving up until the last is evaluated. Here is an example. Again, it will start with single digit numbers in order to be more easily read. Evaluate the prefix expression: ( + ( * 4 2 ) ( 5 2 ) ( * ( + 6 4) (+ 1 1 ) ) ) (* 4 2) can be evaluated, so: ( + 8 ( 5 2 ) ( * ( + 6 4) (+ 1 1 ) ) ) ( 5 2) is defined as 5 2, so: ( ( * ( + 6 4) (+ 1 1 ) ) ) (+ 6 4) can be evaluated, so: ( ( * 10 (+ 1 1 ) ) ) (+ 1 1) can be evaluated, so: ( ( * 10 2 ) ) (* 10 2) can be evaluated, so: ( ) ( ) = 31, so: 31

17 Expression Tree for the Prefix Evaluation The expression is ( + ( * 4 2 ) ( 5 2 ) ( * ( + 6 4) (+ 1 1 ) ) ). Software to evaluate this prefix expression would first build this tree (not very hard to do) and then evaluate it. For example, the node (+ 6 4) would be replaced by 10, etc.

18 Expression Tree Evaluation

19 Single Accumulator Machine Evaluate the expression Z = (X Y) + (W U) This requires an extra storage location, which I call T for Temp. Load X // AC now has X Mult Y // AC now has (X Y) Store T // Now T = (X Y). AC still has (X Y) Load W // AC now has W Mult U // AC now has (W U) Add T // AC now has (X Y) + (W U) Store Z // And so does Z.

20 Multiple Register Machines Evaluate the expression Z = (X Y) + (W U) Standard CISC Approach (There are many variants of this one.) Load R1, X // R1 has X Mult R1, Y // R1 has (X Y) Load R2, W // R2 has W Mult R2, U // R2 has (W U) Add R1, R2 // R1 has (X Y) + (W U) Store R1, Z // And so does Z Load Store RISC Load R1, X // R1 has X Load R2, Y // R2 has Y Mult R1, R2 // R1 has (X Y) Load R2, W // R2 now has W Load R3, U // R3 has U Mult R2, R3 // R2 has (W U) Add R1, R2 // R1 has (X Y) + (W U) Store R1, Z // And so does Z.

21 Data Types Each Instruction Set Architecture has a set of data types for which it provides hardware support. The standard set of data types includes: 1. Character (Single bytes, but soon to be 16 bits to support UNICODE) 2. Integers 8 bit, 16 bit, 32 bit, etc. Signed (Two s Complement) and Unsigned 3. Real Numbers (Usually the IEEE 754 Standard Floating Point) (Usually 32 bit and 64 bit formats are both supported) 4. Boolean TRUE or FALSE, usually stored as a single byte. 0 = FALSE, everything else is TRUE Other languages support additional data types. 5. Decimal Business applications, such as COBOL, avoid floating point arithmetic with its round off errors and use BCD arithmetic. 6. Complex This arithmetic allows for taking the square roots of negative numbers. Usually supported by a software package.

22 Instruction Types There are basic instruction types that are commonly supported. 1. Data Movement (Better called Data Copy ) These copy bytes of data from a source to a destination. If X and Y are 32 bit real numbers, then the instruction Y = X makes a copy of the four bytes associated with X and places them in the address for Y. 2. Arithmetic The standard arithmetic operators are usually supported. If division is supported, one usually also has the mod and rem functions. On business oriented machines, decimal arithmetic is always supported. Graphics oriented machines usually support saturation arithmetic. Real number arithmetic is often not handled directly in the CPU, but by a coprocessor attached to it. Early on (Intel / 80487) this was a cost consideration. RISC machines follow this approach in order to keep the CPU simple. 3. Boolean Logic Here I differ from the book s description. Boolean instructions are often used for non Boolean purposes, such as bit manipulation. The real Boolean instructions are the conditional branches.

23 More Instruction Types 4. Bit Manipulation These use instructions that appear to be Boolean, but in fact operate differently. This is a distinction lost on many students, perhaps because it is rarely important. More on this in a moment. 5. Input / Output The computer must communicate with external devices, including permanent storage, printers and keyboards, process control devices (through dedicated I/O registers), etc. The MARIE architecture has a dedicated input device and a dedicated output device. All commercial machines have addressable I/O devices; i.e., the CPU issues a device identifier that appears to be an address to select the device. From the CPU viewpoint, each I/O device is nothing more than a set of registers (control, status, and data) and some timing constraints. 6. Transfer of Control These alter the normal sequential execution of code. At the primitive machine language level, all we have is unconditional jumps, conditional jumps, and subroutine invocations. Higher level languages elaborate these features with structured constructs such as conditional statements, counted loops, and conditional loops.

24 More on Logical Instructions vs. Bitwise Instructions This is quite important in C, C++, and Java. Consider the standard implementation of Boolean values as 8 bit bytes. This is done for convenience in addressing by the CPU, as single bits are not addressable. Let A = C = B = D = Logical operators in C++ AND && Expression && Expression OR Expression Expression Bitwise operators in C++ AND & Expression & Expression OR Expression Expression XOR ^ Expression ^ Expression Logical Bitwise A && B = 0 (FALSE) A & B = A B = 1 (TRUE) A B = C && D = 1 (TRUE) C & D = C D = 1 (TRUE) C D = Source: The Annotated C++ Reference Manual (Sections ) Margaret Ellis and Bjarne Stroustrup, Addison Wesley, 1990.

25 A Context for Bitwise Operators For simplicity I consider a very old (late 1960 s) Line Printer, a predecessor to today s laser printer. We examine the Status/Control register for the LP 11. This register is called LPS for Line Printer Status in the literature. We have here two status bits and a control bit. Status bits Bit 15 Error If Error = 1, then there is a device error, such as power off, no paper in the printer, etc. Bit 7 Done If Done = 1, the printer is ready for the next line. Control bit Bit 6 IE If IE = 1, the printer is enabled to raise an interrupt whenever Done becomes 1 or Error becomes 1.

26 More on the LPS Register Why this arrangement of bits? The PDP 11, for which the LP 11 was used, did not support 8 bit arithmetic. A 16 bit integer was the smallest that the CPU would handle. Viewed as a 16 bit signed integer, we note that the error bit (Bit 15) is the sign bit. To test for an error, we just read the LPS into a register and test if it is negative. Testing the Done Bit Recall that the Done Bit is bit 7 and that is 0x0080. LPS E DI x LPS & 0x D If ( 0 = = (LPS & 0x0080) ) then the Line Printer is Not Done

27 Still More on the LPS Register Testing and Setting the Interrupt Enable Bit Recall that the Done Bit is bit 6 and that is 0x is 0xFFBF. Testing the Interrupt Enable Bit LPS E DI x LPS & 0x I If ( 0 = = (LPS & 0x0040) ) then the Line Printer Interrupt is disabled.

28 Yet More on the LPS Register Enabling Interrupts (Setting the I Bit) LPS E DI x LPS 0x0040 E D Setting LPS = LPS 0x0040 enables the interrupt and leaves the other bits unchanged. Disabling Interrupts (Clearing the I Bit) LPS E DI xFFBF LPS & 0xFFBF E D Setting LPS = LPS 0xFFBF disables the interrupt and leaves the other bits unchanged.

Problem with Scanning an Infix Expression

Problem with Scanning an Infix Expression Operator Notation Consider the infix expression (X Y) + (W U), with parentheses added to make the evaluation order perfectly obvious. This is an arithmetic expression written in standard form, called infix

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

UNIT-II. Part-2: CENTRAL PROCESSING UNIT Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:

More information

UNIT 3

UNIT 3 UNIT 3 Presentation Outline Sequence control with expressions Conditional Statements, Loops Exception Handling Subprogram definition and activation Simple and Recursive Subprogram Subprogram Environment

More information

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows:

STACKS. A stack is defined in terms of its behavior. The common operations associated with a stack are as follows: STACKS A stack is a linear data structure for collection of items, with the restriction that items can be added one at a time and can only be removed in the reverse order in which they were added. The

More information

The von Neumann Architecture. IT 3123 Hardware and Software Concepts. The Instruction Cycle. Registers. LMC Executes a Store.

The von Neumann Architecture. IT 3123 Hardware and Software Concepts. The Instruction Cycle. Registers. LMC Executes a Store. IT 3123 Hardware and Software Concepts February 11 and Memory II Copyright 2005 by Bob Brown The von Neumann Architecture 00 01 02 03 PC IR Control Unit Command Memory ALU 96 97 98 99 Notice: This session

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

Chapter 7A Overview of Instruction Set Architecture

Chapter 7A Overview of Instruction Set Architecture Overview of This is the first of three chapters in this textbook that correspond to Chapter 7, The Intel Pentium CPU, in the official text for this course, Computer Systems Architecture by Rob Williams.

More information

Understand the factors involved in instruction set

Understand the factors involved in instruction set A Closer Look at Instruction Set Architectures Objectives Understand the factors involved in instruction set architecture design. Look at different instruction formats, operand types, and memory access

More information

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Chapter 5 A Closer Look at Instruction Set Architectures Gain familiarity with memory addressing modes. Understand

More information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand

More information

CHAPTER 5 A Closer Look at Instruction Set Architectures

CHAPTER 5 A Closer Look at Instruction Set Architectures CHAPTER 5 A Closer Look at Instruction Set Architectures 5.1 Introduction 5.2 Instruction Formats 5.2.1 Design Decisions for Instruction Sets 5.2.2 Little versus Big Endian 5.2.3 Internal Storage in the

More information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

CDA 3103 Computer Organization Homework #7 Solution Set

CDA 3103 Computer Organization Homework #7 Solution Set CDA 3103 Computer Organization Homework #7 Solution Set 1 Problems 1. Write a MARIE assembly program for the following algorithm where the subroutine takes two numbers and returns their product. Your assembly

More information

CHAPTER 5 A Closer Look at Instruction Set Architectures

CHAPTER 5 A Closer Look at Instruction Set Architectures CHAPTER 5 A Closer Look at Instruction Set Architectures 5.1 Introduction 199 5.2 Instruction Formats 199 5.2.1 Design Decisions for Instruction Sets 200 5.2.2 Little versus Big Endian 201 5.2.3 Internal

More information

CHAPTER 5 A Closer Look at Instruction Set Architectures

CHAPTER 5 A Closer Look at Instruction Set Architectures CHAPTER 5 A Closer Look at Instruction Set Architectures 5.1 Introduction 293 5.2 Instruction Formats 293 5.2.1 Design Decisions for Instruction Sets 294 5.2.2 Little versus Big Endian 295 5.2.3 Internal

More information

17. Instruction Sets: Characteristics and Functions

17. Instruction Sets: Characteristics and Functions 17. Instruction Sets: Characteristics and Functions Chapter 12 Spring 2016 CS430 - Computer Architecture 1 Introduction Section 12.1, 12.2, and 12.3 pp. 406-418 Computer Designer: Machine instruction set

More information

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation Course Schedule CS 221 Computer Architecture Week 3: Information Representation (2) Fall 2001 W1 Sep 11- Sep 14 Introduction W2 Sep 18- Sep 21 Information Representation (1) (Chapter 3) W3 Sep 25- Sep

More information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand

More information

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram:

The CPU and Memory. How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: The CPU and Memory How does a computer work? How does a computer interact with data? How are instructions performed? Recall schematic diagram: 1 Registers A register is a permanent storage location within

More information

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation Computer Organization CS 231-01 Data Representation Dr. William H. Robinson November 12, 2004 Topics Power tends to corrupt; absolute power corrupts absolutely. Lord Acton British historian, late 19 th

More information

ARM Cortex A9. ARM Cortex A9

ARM Cortex A9. ARM Cortex A9 ARM Cortex A9 Four dedicated registers are used for special purposes. The IP register works around the limitations of the ARM functional call instruction (BL) which cannot fully address all of its 2 32

More information

Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

More information

Special Section: Building Your Own Compiler

Special Section: Building Your Own Compiler cshtp6_19_datastructures_compiler.fm Page 1 Tuesday, February 14, 2017 10:31 AM 1 Chapter 19 Special Section: Building Your Own Compiler In Exercises8.31 8.33, we introduced Simpletron Machine Language

More information

COMPUTER ORGANIZATION & ARCHITECTURE

COMPUTER ORGANIZATION & ARCHITECTURE COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional

More information

Formal Languages and Automata Theory, SS Project (due Week 14)

Formal Languages and Automata Theory, SS Project (due Week 14) Formal Languages and Automata Theory, SS 2018. Project (due Week 14) 1 Preliminaries The objective is to implement an algorithm for the evaluation of an arithmetic expression. As input, we have a string

More information

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION

09 STACK APPLICATION DATA STRUCTURES AND ALGORITHMS REVERSE POLISH NOTATION DATA STRUCTURES AND ALGORITHMS 09 STACK APPLICATION REVERSE POLISH NOTATION IMRAN IHSAN ASSISTANT PROFESSOR, AIR UNIVERSITY, ISLAMABAD WWW.IMRANIHSAN.COM LECTURES ADAPTED FROM: DANIEL KANE, NEIL RHODES

More information

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer Overview EE 4504 Computer Organization Section 7 The Instruction Set Much of the computer s architecture / organization is hidden from a HLL programmer In the abstract sense, the programmer should not

More information

Why Study Assembly Language?

Why Study Assembly Language? Why Study Assembly Language? This depends on the decade in which you studied assembly language. 1940 s You cannot study assembly language. It does not exist yet. 1950 s You study assembly language because,

More information

Instruc=on Set Architecture

Instruc=on Set Architecture ECPE 170 Jeff Shafer University of the Pacific Instruc=on Set Architecture 2 Schedule Today and Wednesday Closer look at instruc=on sets Fri Quiz 4 (over Chapter 5, i.e. HW #11 and HW #12) 3 Endianness

More information

When an instruction is initially read from memory it goes to the Instruction register.

When an instruction is initially read from memory it goes to the Instruction register. CS 320 Ch. 12 Instruction Sets Computer instructions are written in mnemonics. Mnemonics typically have a 1 to 1 correspondence between a mnemonic and the machine code. Mnemonics are the assembly language

More information

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1 Some Applications of Stack Spring Semester 2007 Programming and Data Structure 1 Arithmetic Expressions Polish Notation Spring Semester 2007 Programming and Data Structure 2 What is Polish Notation? Conventionally,

More information

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI Starting Chapter 2: CSCI 402: Computer Architectures Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI Contents 2.1 and 2.3 What is instruction?

More information

Subprograms, Subroutines, and Functions

Subprograms, Subroutines, and Functions Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the

More information

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved

Stacks. Chapter 5. Copyright 2012 by Pearson Education, Inc. All rights reserved Stacks Chapter 5 Copyright 2012 by Pearson Education, Inc. All rights reserved Contents Specifications of the ADT Stack Using a Stack to Process Algebraic Expressions A Problem Solved: Checking for Balanced

More information

infix expressions (review)

infix expressions (review) Outline infix, prefix, and postfix expressions queues queue interface queue applications queue implementation: array queue queue implementation: linked queue application of queues and stacks: data structure

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science COS 140: Foundations of Computer Science CPU Organization and Assembly Language Fall 2018 CPU 3 Components of the CPU..................................................... 4 Registers................................................................

More information

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures Chapter 5 A Closer Look at Instruction Set Architectures Chapter 5 Objectives Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand

More information

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats Chapter 5 Objectives Chapter 5 A Closer Look at Instruction Set Architectures Understand the factors involved in instruction set architecture design. Gain familiarity with memory addressing modes. Understand

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

In this chapter you ll learn:

In this chapter you ll learn: Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading on

More information

CISC

CISC CISC-235 20180115+17+19 Much of the material we covered this week was already posted in the notes for last week. These notes take up where those left off, and fill in some gaps. We have discussed the notation

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

The Stack and Queue Types

The Stack and Queue Types The Stack and Queue Types Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html 2 Programming Principle of the Day Do the simplest thing that could possibly work A good

More information

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard

IV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard IV. Stacks 1 A. Introduction 1. Consider the problems on pp. 170-1 (1) Model the discard pile in a card game (2) Model a railroad switching yard (3) Parentheses checker () Calculate and display base-two

More information

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd 19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading

More information

Full file at

Full file at Chapter Two DATA MANIPULATION Formatted Chapter Summary This chapter introduces the role of a computer's CPU. It describes the machine cycle and the various operations (or, and, exclusive or, add, shift,

More information

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed "stack method of expression evaluation" in 1955.

-The Hacker's Dictionary. Friedrich L. Bauer German computer scientist who proposed stack method of expression evaluation in 1955. Topic 15 Implementing and Using "stack n. The set of things a person has to do in the future. "I haven't done it yet because every time I pop my stack something new gets pushed." If you are interrupted

More information

The MARIE Architecture

The MARIE Architecture The MARIE Machine Architecture that is Really Intuitive and Easy. We now define the ISA (Instruction Set Architecture) of the MARIE. This forms the functional specifications for the CPU. Basic specifications

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

(Refer Slide Time: 1:40)

(Refer Slide Time: 1:40) Computer Architecture Prof. Anshul Kumar Department of Computer Science and Engineering, Indian Institute of Technology, Delhi Lecture - 3 Instruction Set Architecture - 1 Today I will start discussion

More information

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation

Chapter 04: Instruction Sets and the Processor organizations. Lesson 18: Stack-based processor Organisation Chapter 04: Instruction Sets and the Processor organizations Lesson 18: Stack-based processor Organisation 1 Objective To understand stack based processor organisation Instruction set of a stack organized

More information

CISC-235. At this point we fnally turned our atention to a data structure: the stack

CISC-235. At this point we fnally turned our atention to a data structure: the stack CISC-235 20180918 At this point we fnally turned our atention to a data structure: the stack A stack is our frst example of an Abstract Data Type: we specify the operations we need to be able to perform

More information

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this:

SimpleCalc. which can be entered into a TI calculator, like the one on the right, like this: !! SimpleCalc Objective: To use stacks to emulate a simple arithmetic calculator. Background: Most people learn to write arithmetic expressions like this: which can be entered into a TI calculator, like

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

CHAPTER 8: Central Processing Unit (CPU)

CHAPTER 8: Central Processing Unit (CPU) CS 224: Computer Organization S.KHABET CHAPTER 8: Central Processing Unit (CPU) Outline Introduction General Register Organization Stack Organization Instruction Formats Addressing Modes 1 Major Components

More information

ECE232: Hardware Organization and Design

ECE232: Hardware Organization and Design ECE232: Hardware Organization and Design Lecture 4: Logic Operations and Introduction to Conditionals Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Overview Previously examined

More information

Logic, Words, and Integers

Logic, Words, and Integers Computer Science 52 Logic, Words, and Integers 1 Words and Data The basic unit of information in a computer is the bit; it is simply a quantity that takes one of two values, 0 or 1. A sequence of k bits

More information

EC-801 Advanced Computer Architecture

EC-801 Advanced Computer Architecture EC-801 Advanced Computer Architecture Lecture 5 Instruction Set Architecture I Dr Hashim Ali Fall 2018 Department of Computer Science and Engineering HITEC University Taxila!1 Instruction Set Architecture

More information

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss

Grundlagen Microcontroller Processor Core. Günther Gridling Bettina Weiss Grundlagen Microcontroller Processor Core Günther Gridling Bettina Weiss 1 Processor Core Architecture Instruction Set Lecture Overview 2 Processor Core Architecture Computes things > ALU (Arithmetic Logic

More information

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO)

Stacks. stacks of dishes or trays in a cafeteria. Last In First Out discipline (LIFO) Outline stacks stack ADT method signatures array stack implementation linked stack implementation stack applications infix, prefix, and postfix expressions 1 Stacks stacks of dishes or trays in a cafeteria

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit - 1

Darshan Institute of Engineering & Technology for Diploma Studies Unit - 1 Darshan Institute of Engineering & Technology for Diploma Studies Unit - 1 1. Draw and explain 4 bit binary arithmetic or adder circuit diagram. A binary parallel adder is digital function that produces

More information

Instruction Sets: Characteristics and Functions

Instruction Sets: Characteristics and Functions Instruction Sets: Characteristics and Functions Chapter 10 Lesson 15 Slide 1/22 Machine instruction set Computer designer: The machine instruction set provides the functional requirements for the CPU.

More information

Instruction Set Architectures. CS301 Prof. Szajda

Instruction Set Architectures. CS301 Prof. Szajda Instruction Set Architectures CS301 Prof. Szajda Instruction Categories Arithmetic w x = x + 1 Memory w mem[addr] = x; Control w for(int i = 0; i < 10 ; i++) Arguments to Arithmetic Operations Constant:

More information

DEEPIKA KAMBOJ UNIT 2. What is Stack?

DEEPIKA KAMBOJ UNIT 2. What is Stack? What is Stack? UNIT 2 Stack is an important data structure which stores its elements in an ordered manner. You must have seen a pile of plates where one plate is placed on top of another. Now, when you

More information

Run time environment of a MIPS program

Run time environment of a MIPS program Run time environment of a MIPS program Stack pointer Frame pointer Temporary local variables Return address Saved argument registers beyond a0-a3 Low address Growth of stack High address A translation

More information

Memory Addressing, Binary, and Hexadecimal Review

Memory Addressing, Binary, and Hexadecimal Review C++ By A EXAMPLE Memory Addressing, Binary, and Hexadecimal Review You do not have to understand the concepts in this appendix to become well-versed in C++. You can master C++, however, only if you spend

More information

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI

CSCI 402: Computer Architectures. Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI To study Chapter 2: CSCI 402: Computer Architectures Instructions: Language of the Computer (1) Fengguang Song Department of Computer & Information Science IUPUI Contents 2.1-2.3 Introduction to what is

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures PD Dr. rer. nat. habil. Ralf Peter Mundani Computation in Engineering / BGU Scientific Computing in Computer Science / INF Summer Term 2018 Part 2: Data Structures PD Dr.

More information

Stacks. Revised based on textbook author s notes.

Stacks. Revised based on textbook author s notes. Stacks Revised based on textbook author s notes. Stacks A restricted access container that stores a linear collection. Very common for solving problems in computer science. Provides a last-in first-out

More information

2. ADDRESSING METHODS

2. ADDRESSING METHODS 2 Addressing Methods STUDY MATERIALS ON COMPUTER ORGANIZATION (As per the curriculum of Third semester BSc Electronics of Mahatma Gandh Uniiversity) Compiled by Sam Kollannore U Lecturer in Electronics

More information

Lecture No.04. Data Structures

Lecture No.04. Data Structures Lecture No.04 Data Structures Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3; for(i=1; i

More information

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 )

ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) ADVANCED DATA STRUCTURES USING C++ ( MT-CSE-110 ) Unit - 2 By: Gurpreet Singh Dean Academics & H.O.D. (C.S.E. / I.T.) Yamuna Institute of Engineering & Technology, Gadholi What is a Stack? A stack is a

More information

Architectures. CHAPTER 5 Instruction Set 5.1 INTRODUCTION 5.2 INSTRUCTION FORMATS

Architectures. CHAPTER 5 Instruction Set 5.1 INTRODUCTION 5.2 INSTRUCTION FORMATS CHAPTER 5 Instruction Set Architectures 5.1 INTRODUCTION e saw in Chapter 4 that machine instructions consist of opcodes and Woperands. The opcodes specify the operations to be executed; the operands specify

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points]

Review Questions. 1 The DRAM problem [5 points] Suggest a solution. 2 Big versus Little Endian Addressing [5 points] Review Questions 1 The DRAM problem [5 points] Suggest a solution 2 Big versus Little Endian Addressing [5 points] Consider the 32-bit hexadecimal number 0x21d3ea7d. 1. What is the binary representation

More information

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set?

Instruction Set II. COMP 212 Computer Organization & Architecture. COMP 212 Fall Lecture 7. Instruction Set. Quiz. What is an Instruction Set? COMP 212 Computer Organization & Architecture Quiz COMP 212 Fall 2008 Lecture 7 Fill in your student number only, do NOT write down your name Open book, but NO calculator, NO discussions, Relax and have

More information

Outline. Stacks. 1 Chapter 5: Stacks and Queues. favicon. CSI33 Data Structures

Outline. Stacks. 1 Chapter 5: Stacks and Queues. favicon. CSI33 Data Structures Outline Chapter 5: and Queues 1 Chapter 5: and Queues Chapter 5: and Queues The Stack ADT A Container Class for Last-In-First-Out Access A stack is a last in, first out (LIFO) structure, i.e. a list-like

More information

Instruction content (2/2) Instruction content (1/2) The Instruction Set. Chapter 9. Each instruction must contain 4 basic pieces of information

Instruction content (2/2) Instruction content (1/2) The Instruction Set. Chapter 9. Each instruction must contain 4 basic pieces of information CS.216 Computer Architecture and Organization Chapter 9 The Instruction Set L/O/G/O www.themegallery.com Overview Much of the computer s architecture / organization is hidden from a HLL programmer In the

More information

Microcontrollers. Microcontroller

Microcontrollers. Microcontroller Microcontrollers Microcontroller A microprocessor on a single integrated circuit intended to operate as an embedded system. As well as a CPU, a microcontroller typically includes small amounts of RAM and

More information

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS The Microprocessor without Interlocked Pipeline Stages

More information

What Is It? Instruction Register Address Register Data Register

What Is It? Instruction Register Address Register Data Register What Is It? Consider the following set of 32 binary digits, written in blocks of four so that the example is not impossible to read. 0010 0110 0100 1100 1101 1001 1011 1111 How do we interpret this sequence

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

Basic data types. Building blocks of computation

Basic data types. Building blocks of computation Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

More information

Project 3: RPN Calculator

Project 3: RPN Calculator ECE267 @ UIC, Spring 2012, Wenjing Rao Project 3: RPN Calculator What to do: Ask the user to input a string of expression in RPN form (+ - * / ), use a stack to evaluate the result and display the result

More information

TYPES OF INTERRUPTS: -

TYPES OF INTERRUPTS: - There are 3 types of interrupts. TYPES OF INTERRUPTS: - External Interrupts. Internal Interrupts. Software interrupts. Hardware Interrupts (1) External interrupts come from I/O devices, from a timing device

More information

Stacks Fall 2018 Margaret Reid-Miller

Stacks Fall 2018 Margaret Reid-Miller Stacks 15-121 Fall 2018 Margaret Reid-Miller Today Exam 2 is next Tuesday, October 30 Today: Quiz 5 solutions Recursive add from last week (see SinglyLinkedListR.java) Stacks ADT (Queues on Thursday) ArrayStack

More information

Chapter 14 Design of the Central Processing Unit

Chapter 14 Design of the Central Processing Unit Chapter 14 Design of the Central Processing Unit We now focus on the detailed design of the CPU (Central Processing Unit) of the Boz 7. The CPU has two major components: the Control Unit and the ALU (Arithmetic

More information

Draw a diagram of an empty circular queue and describe it to the reader.

Draw a diagram of an empty circular queue and describe it to the reader. 1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the

More information

COMPUTER HARDWARE. Instruction Set Architecture

COMPUTER HARDWARE. Instruction Set Architecture COMPUTER HARDWARE Instruction Set Architecture Overview Computer architecture Operand addressing Addressing architecture Addressing modes Elementary instructions Data transfer instructions Data manipulation

More information

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA)

COMP2121: Microprocessors and Interfacing. Instruction Set Architecture (ISA) COMP2121: Microprocessors and Interfacing Instruction Set Architecture (ISA) http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 Contents Memory models Registers Data types Instructions

More information

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1 CSIS1120A 10. Instruction Set & Addressing Mode CSIS1120A 10. Instruction Set & Addressing Mode 1 Elements of a Machine Instruction Operation Code specifies the operation to be performed, e.g. ADD, SUB

More information

Final Examination: Topics and Sample Problems

Final Examination: Topics and Sample Problems Computer Science 52 Final Examination: Topics and Sample Problems Spring Semester, 2015 In examinations the foolish ask questions that the wise cannot answer. Oscar Wilde, 1894 Time and Place Wednesday,

More information

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract Data Types Stack January 26, 2018 Cinda Heeren / Geoffrey Tien 1 Abstract data types and data structures An Abstract Data Type (ADT) is: A collection of data Describes what data are stored but

More information

CS 211 Programming Practicum Spring 2017

CS 211 Programming Practicum Spring 2017 Due: Tuesday, 3/28/17 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a JAVA program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3 UNIT 3 LINEAR DATA STRUCTURES 1. Define Data Structures Data Structures is defined as the way of organizing all data items that consider not only the elements stored but also stores the relationship between

More information

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017 COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface RISC-V Edition Chapter 2 Instructions: Language of the Computer These slides are based on the slides by the authors. The slides doesn t

More information

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions Structure of von Nuemann machine Arithmetic and Logic Unit Input Output Equipment Main Memory Program Control Unit 1 1 Instruction Set - the type of Instructions Arithmetic + Logical (ADD, SUB, MULT, DIV,

More information

Computer Architecture Prof. Smruti Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Computer Architecture Prof. Smruti Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi Computer Architecture Prof. Smruti Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 11 X86 Assembly Language Part-II (Refer Slide Time: 00:25)

More information