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

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

CPU Review and Programming Models CT101 – Computing Systems.
There are two types of addressing schemes:
Stacks & Their Applications COP Stacks  A stack is a data structure that stores information arranged like a stack.  We have seen stacks before.
Infix, Postfix and Stacks
COSC 2006 Chapter 7 Stacks III
Chapter 4 Processor Technology and Architecture. Chapter goals Describe CPU instruction and execution cycles Explain how primitive CPU instructions are.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
Computer Architecture
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Lecture 18 Last Lecture Today’s Topic Instruction formats
Lecture 17 Today’s Lecture –Instruction formats Little versus big endian Internal storage in the CPU: stacks vs. registers Number of operands and instruction.
Lecture 3. Diff b/w RAM and Registers Registers are used to hold data immediately applicable to the operation at hand Registers are used to hold data.
Instruction Set Architecture
Software Overview. Why review software? Software is the set of instructions that tells hardware what to do The reason for hardware is to execute a program.
Microcode Source: Digital Computer Electronics (Malvino and Brown)
CSIT 301 (Blum)1 Software Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
CSC321 Making a Computer Binary number system → Boolean functions Boolean functions → Combinational circuits Combinational circuits → Sequential circuits.
Chapter 5 A Closer Look at Instruction Set Architectures.
Chapter 5 A Closer Look at Instruction Set Architectures.
PHY 201 (Blum)1 Microcode Source: Digital Computer Electronics (Malvino and Brown)
CSC 370 (Blum)1 Instructions From the Bottom Up Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.
Instructions. Portability In addition to making hardware backward compatible, we have also made software portable. In describing software, “portable”
Copyright © Curt Hill Stacks An Useful Abstract Data Type.
Structure and Role of a Processor
PHY 201 (Blum)1 Stacks Based in part on material from Chapters 4 & 5 in Computer Architecture by Nicholas Carter.
Winter 2016CISC101 - Prof. McLeod1 Today Numeric representation (or “How does binary and hexadecimal work?”). How can a CPU understand instructions written.
1 Processor design Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.3.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Variables, Operators, and Expressions
Review Use of Stack Introduction Stack in our life Stack Operations
Displacement (Indexed) Stack
Expressions and Assignment
A Closer Look at Instruction Set Architectures
Instructions From the Bottom Up
Computing Fundamentals
CHAPTER 6: The Little Man Computer
A Closer Look at Instruction Set Architectures
Computer Organization and Design
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
William Stallings Computer Organization and Architecture 8th Edition
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Stacks Chapter 4.
Algorithms and Data Structures
Instructions at the Lowest Level
Introduction to Micro Controllers & Embedded System Design Stored Program Machine Department of Electrical & Computer Engineering Missouri University.
Instructions From the Bottom Up
BASIC COMPUTER ORGANIZATION AND DESIGN
Stacks Chapter 5 Adapted from Pearson Education, Inc.
Expressions Chapter 4 Copyright © 2008 W. W. Norton & Company.
Winter 2018 CISC101 11/29/2018 CISC101 Reminders
Fundamentals of Computer Organisation & Architecture
Chapter 8 Central Processing Unit
Processor Organization and Architecture
ECEG-3202 Computer Architecture and Organization
BIC 10503: COMPUTER ARCHITECTURE
A Closer Look at Instruction Set Architectures Chapter 5
Cs212: Data Structures Computer Science Department Lecture 6: Stacks.
Queue Applications Lecture 31 Mon, Apr 9, 2007.
CPU has 6 special locations called registers
Processor design Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.3.
Chapter 7 Expressions and Assignment Statements.
CISC101 Reminders Labs start this week. Meet your TA! Get help with:
Floating Point Numbers
Instructions.
Computer Operation 6/22/2019.
Processor design Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 11.3.
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Presented by : Aman Gupta PGT CS KV No.1, Narimedu, Madurai
Presentation transcript:

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

Instruction Set One aspect of processor design is to determine what instructions will be supported. There must be rules (syntax) for how instructions are expressed so that the code can be parsed, one instruction distinguished from the next, the data (operand) separated from the action (operator). PHY 201 (Blum)

Number of operands An example of syntax would be whether an operator is binary or unary Binary operators take two operands e.g. the boolean operator AND (x<y) AND (i=j) Unary operator take one operand E.g. the boolean operator NOT NOT(x<y) Some ops are context dependent - 5 (unary) versus 4-5 (binary) PHY 201 (Blum)

Operation versus Instruction An operation such as addition, which is binary (takes two operands), can be coded using instructions that are unary (one operand) if there is a default location implied such as Accumulator A. 5 + 6 becomes Load 5 (places data in acc. A) Add 6 (adds number in Acc. A to new number) PHY 201 (Blum)

Where does the answer go? Whether it’s 5 + 6 or (Load 5, Add 6), there’s the question of what to do with the result. We can again use the default location of Accumulator A to place the answer in or we can include a third operand that indicates where the result should be placed. PHY 201 (Blum)

Store Placing the result of an operation in memory is known as storing it. Thus with unary instructions, we would have Load 5 Add 6 Store 7 The operand of the store is an address indicating where to store the answer, which is held in Accumulator A. Or one might have three operands Add 7, 5, 6 PHY 201 (Blum)

Addressing Modes But this raises the question as to what were the operands in the two previous instructions (Load and Add). For those instructions, the operand might have been the actual numbers one wanted added or the addresses of numbers one wanted added. PHY 201 (Blum)

More than one kind of add By Add one typically means the latter case on the previous slide. The operand is not the number to be added but the address of the number to be added. A designer can include a distinct add instruction, Add Immediate, in which the operand is the actual number to be added. PHY 201 (Blum)

Add Indirect In another version of addition, the operand is an address, and the data at that address is also an address, and the actual number to added is located at the second address. PHY 201 (Blum)

A short program Acc. A: XXX Address Value LOAD 4 1 ADD INDIRECT 5 2 ADD IMMEDIATE 6 3 STOP 4 5 6 7 8 Acc. A: XXX The arrow indicates the program counter, we assume it has not executed the statement it points to. PHY 201 (Blum)

A short program Address Value LOAD 4 1 ADD INDIRECT 5 2 ADD IMMEDIATE 6 3 STOP 4 5 6 7 8 Acc. A: 5 The Load 4 instruction has been executed. The value at location 4 (which is a 5) has been loaded into the accumulator. PHY 201 (Blum)

A short program Address Value LOAD 4 1 ADD INDIRECT 5 2 ADD IMMEDIATE 6 3 STOP 4 5 6 7 8 Acc. A: 12 The Add Indirect 5 instruction has been executed. One goes to location 5 to find a value of 6. That 6 is an address, thus one goes to location 6 to find a value of 7 and that is added to the 5 waiting in the accumulator. The result of 12 is placed in the accumulator. PHY 201 (Blum)

A short program Address Value LOAD 4 1 ADD INDIRECT 5 2 ADD IMMEDIATE 6 3 STOP 4 5 6 7 8 Acc. A: 18 The Add Immediate 6 instruction has been executed. The value 6 is data which is added to the 12 waiting in the accumulator. The result of 18 is placed in the accumulator. PHY 201 (Blum)

The Stop Instruction Recall that in what is actually executed (machine code) the instructions themselves numbers. Thus it is crucial to know within an instruction which numbers correspond to an operation and which numbers are operands. Similarly on the level of the program itself, the processor needs to know where the program ends as there may be data stored after it. In a machine with an operating system, it is more a notion of returning (control) than of stopping or halting. PHY 201 (Blum)

Recap so far So there were issues about the number of operands. Recall that we have a fetch-execute cycle – first an instruction is retrieved from memory and then acted upon. With unary instructions adding two numbers and storing the result required three instructions, that’s three fetches and three executions. With ternary instructions it can be done with one instruction, one fetch and one execute. The execution is now more complicated but we have saved time on fetches. PHY 201 (Blum)

Recap so far (Cont.) More operators means more complicated circuitry, the load and store aspects of the instruction would have to built into each separate instruction. There is a speed versus complexity issue. And complexity also brings the issue of cost along with it. PHY 201 (Blum)

Recap so far (Cont.) After determining the number of operands came the issue of what the operands mean. Are they data, addresses of data or addresses of addresses of data? Either we can decide to support all of these and choose complexity. Or we can choose to support only some of them and sacrifice efficiency. For example, you can eliminate Add Immediate if you always store the values you want to add. PHY 201 (Blum)

Data Types Apart from addressing, another issue is the type of data the operation is acting on. The process for adding integers is different from the process for adding floating point numbers. So one may have separate instructions: ADD for addition of integers and FADD for the addition floats. Furthermore, one may need to include instructions to convert from one type to another. To add an integer to a float, convert the integer to a float and then add the floats. PHY 201 (Blum)

Ordering of opcodes and operands Another example of syntax is the ordering of opcode and operand(s). 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)

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 * 3 - 4 1 + 6 - 4 (multiplication has higher precedence) 7 - 4 (start on the left when operators have the same precedence) 3 PHY 201 (Blum)

Infix to postfix To convert 1+2*3-4, put in parentheses even though they’re not strictly necessary for this expression ((1+(2*3))-4) Convert the innermost parentheses to postfix: 2*3 becomes 2 3 * ((1+(2 3 *))-4) Convert the next set of parentheses ((1 2 3 * +)-4) PHY 201 (Blum)

Infix to postfix The last step eliminated the innermost set of parentheses. Continue to convert from infix to postfix from the innermost to outermost parentheses. (1 2 3 * + 4 -) Note there is one overall set of parentheses that can be thrown away. Also note that the order of the numbers has not changed. PHY 201 (Blum)

Another example 1+ (2+3) * 4 + (5 + 6) * ((7 + 8) * 9) Add parentheses 1+ ((2+3) * 4) + ((5 + 6) * ((7 + 8) * 9)) (1+ ((2+3) * 4)) + ((5 + 6) * ((7 + 8) * 9)) ((1+ ((2+3) * 4)) + ((5 + 6) * ((7 + 8) * 9))) Convert innermost to postfix ((1+ ((2 3 +) * 4)) + ((5 6 +) * ((7 8 +) * 9))) PHY 201 (Blum)

Another Example (Cont.) ((1+ ((2 3 +) * 4)) + ((5 6 +) * ((7 8 +) * 9))) ((1+ (2 3 + 4 * )) + ((5 6 +) * (7 8 + 9 * ))) ((1 2 3 + 4 * +) + (5 6 + 7 8 + 9 * *)) ( 1 2 3 + 4 * + 5 6 + 7 8 + 9 * * + ) PHY 201 (Blum)

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

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). PHY 201 (Blum)

Stack 2 is pushed onto the stack 2 is popped off of the stack 4 2 3 3 1 1 1 1 1 PHY 201 (Blum)

Stack Pointer: don’t move all the data just change the pointer X 4 3 1 X 1 X x 2 1 X 2 1 X 3 1 PHY 201 (Blum)

Infix Evaluation 1+ (2+3) * 4 + (5 + 6) * ((7 + 8) * 9) 1+(5)*4 + (11)*((15)*9) 1 + 20 + 11*135 1 + 20 + 1485 21 + 1485 1506 PHY 201 (Blum)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

References Computer Architecture, Nicholas Carter Computers Systems: Organization and Architecture, John Carpinelli http://www.cs.orst.edu/~minoura/cs261/javaProgs/stack/Polish.html PHY 201 (Blum)