CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012.

Slides:



Advertisements
Similar presentations
Stored Program Architecture
Advertisements

Central Processing Unit
2.3) Example of program execution 1. instruction  B25 8 Op-code B means to change the value of the program counter if the contents of the indicated register.
Microprocessor.  The CPU of Microcomputer is called microprocessor.  It is a CPU on a single chip (microchip).  It is called brain or heart of the.
CSE115: Introduction to Computer Science I
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
Room: E-3-31 Phone: Dr Masri Ayob TK 2123 COMPUTER ORGANISATION & ARCHITECTURE Lecture 5: CPU and Memory.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Computing Components 01/26/11. Announcements & Reminders Programs 1 due Friday, 9/2/11 What is my late policy? Proxy Codes for Labs  You should be able.
Stored Program Concept: The Hardware View
Chapter 7 Low-Level Programming Languages. 2 Chapter Goals List the operations that a computer can perform Discuss the relationship between levels of.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Chapters 5 - The LC-3 LC-3 Computer Architecture Memory Map
Basic Computer Organization, CPU L1 Prof. Sin-Min Lee Department of Computer Science.
Dale & Lewis Chapter 5 Computing components. Let’s design a computer Generic CPU with registers −Program counter (PC) – 5 bits (size of addresses) −Instruction.
1 Sec (2.3) Program Execution. 2 In the CPU we have CU and ALU, in CU there are two special purpose registers: 1. Instruction Register 2. Program Counter.
Processor Types And Instruction Sets Barak Perelman CS147 Prof. Lee.
Lecture 13 - Introduction to the Central Processing Unit (CPU)
Computer Science 210 Computer Organization The Instruction Execution Cycle.
A-Level Computing#BristolMet Session Objectives#5 MUST identify different buses and registers used in a CPU SHOULD describe the use of buses to send information.
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.
How Computers Work Dr. John P. Abraham Professor UTPA.
Information Representation: Machine Instructions
Computer Systems Organization CS 1428 Foundations of Computer Science.
GCSE Computing#BristolMet Session Objectives#11 MUST identify what program instructions consist of SHOULD describe how instructions are coded as bit patterns.
Topic 1Topic 2Topic 3Topic 4Topic
Von Neumann Machine Objectives: Explain Von Neumann architecture:  Memory –Organization –Decoding memory addresses, MAR & MDR  ALU and Control Unit –Executing.
The Central Processing Unit (CPU) and the Machine Cycle.
Little Man Computer When your program gets “translated to machine code” all 0’s & 1’s The translator must know the language of the program (java) as well.
Computer Science 101 Computer Systems Organization ALU, Control Unit, Instruction Set.
Computer Hardware A computer is made of internal components Central Processor Unit Internal External and external components.
Computer Architecture Lecture 03 Fasih ur Rehman.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Information Representation: Machine Instructions.
September 26, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 2: Implementation of a Simplified Computer Jeremy R. Johnson Wednesday,
COMPILERS CLASS 22/7,23/7. Introduction Compiler: A Compiler is a program that can read a program in one language (Source) and translate it into an equivalent.
1.4 Representation of data in computer systems Instructions.
An Example Architecture. A Paper Computer - Woody Woody's characteristics Word size – 8 bits One word.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Dale & Lewis Chapter 5 Computing components
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Question What technology differentiates the different stages a computer had gone through from generation 1 to present?
CMSC 104, Lecture 061 Stored Programs A look at how programs are executed.
Translating Assembly Language to Machine Language.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Computer Operation. Binary Codes CPU operates in binary codes Representation of values in binary codes Instructions to CPU in binary codes Addresses in.
Control Unit Lecture 6.
CPU Organisation & Operation
Edexcel GCSE Computer Science Topic 15 - The Processor (CPU)
Computer Architecture
Chapter 4 The Von Neumann Model
Computer Science 210 Computer Organization
Data Representation – Instructions
The fetch-execute cycle
The Processor and Machine Language
Computer Science 210 Computer Organization
CS149D Elements of Computer Science
CSCE Fall 2013 Prof. Jennifer L. Welch.
Topic 6 LC-3.
The Little Man Computer
CSCE Fall 2012 Prof. Jennifer L. Welch.
Program Execution.
The Von Neumann Machine
Basic components Instruction processing
CS334: MIPS language _Mars simulator Lab 2_1
Information Representation: Machine Instructions
Instruction execution and ALU
Computer Architecture Assembly Language
Computer Architecture
CS 111 – Sept. 16 Machine language examples Instruction execution
Sec (2.3) Program Execution.
Presentation transcript:

CMSC 150 PROGRAM EXECUTION CS 150: Wed 1 Feb 2012

Stored Program Concept CPU ALU control unit … registers … …

Our Example Architecture Main Memory …

Our Example Architecture … Main Memory Address

Our Example Architecture Main Memory Instruction Register Program Counter Register Data Register Central Processing Unit … Address

Our Machine Language Assembly Language Instruction Machine Language Instruction CopyFrom000 CopyTo001 Add010 Subtract011 Read100 Print101 IfNegGoTo110 Stop111

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8 …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8  To represent 2 3 = 8 total instructions, need 3 bits …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8  To represent 2 3 = 8 total instructions, need 3 bits  Leaves 5 bits to represent addresses …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8  To represent 2 3 = 8 total instructions, need 3 bits  Leaves 5 bits to represent addresses 5 bits for addresses: 2 5 = 32 memory cells …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8  To represent 2 3 = 8 total instructions, need 3 bits  Leaves 5 bits to represent addresses 5 bits for addresses: 2 5 = 32 memory cells …

Our Hypothetical Computer Main Memory Instruction Register Program Counter Register Data Register CPU Word size: 8 bits (1 byte) Number of instructions: 8  To represent 2 3 = 8 total instructions, need 3 bits  Leaves 5 bits to represent addresses 5 bits for addresses: 2 5 = 32 memory cells …

Data In Our Computer Use sign-magnitude to represent integers 8 bits for data – leftmost bit will be sign (0: non-neg; 1: neg) – 7 remaining bits: magnitude in binary = = -11

Eight Machine Language Instructions Instruction Code Meaning of the Instruction 000Copy word from memory address into DR 001Copy word to memory address from DR 010Add word in memory address to word in DR 011Subtract word in memory address from word in DR 100Read word from input into DR 101Print word in DR to output 110 Conditional execution : If word in DR is negative, copy a new memory address into PC 111Stop execution Underline: an argument (value) required by that instruction

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution one word (here, one byte)

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Instruction code

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Argument (memory address)

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction:

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Copy to …

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Copy to …

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Copy to address 10110…

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Copy to address from DR This instruction copies the contents of the data register into memory cell addressed = 22 10

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Read from input…

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Read from input… No argument…

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Read from input… No argument, hence zeros (to fill the byte)

Example of an Instruction CodeMeaning of the Instruction 000Copy from address into DR 001Copy to address from DR 010Add word in address to DR 011Subtract word in address from DR 100Read from input into DR 101Print to output from DR 110If DR is < 0, copy address into PC 111Stop execution Decoding the Instruction: Read from input into DR This instruction copies a word from the input unit into the data register

Preparing To Execute a Program  Your program is first written in a high-level language (e.g., Java): source code  Converted into machine language: executable  To run, executable is copied into main memory  PC is loaded with the memory address of the first instruction in the executable

Fetch-Execute Cycle 1. Copy the word referred to by the PC into the IR (i.e., fetch) 2. Increment the address stored in the PC 3. Decode & execute the contents of the IR 4. Unless a stop instruction, goto step 1

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit Initial state of memory after loading program and setting PC to Executable Program

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC into Instruction Register 2

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC into Instruction Register 3

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC into Instruction Register 4

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment the Program Counter 5

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and Execute instruction 6

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and Execute instruction – 000 is op code for CopyFrom 7

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and Execute instruction – is address to copy from 8

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and Execute instruction – contains a word 9

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and Execute instruction – Instruction execution is complete 10

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit Repeat: 1. Copy word referred to by PC to IR 11

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit Repeat: 1. Copy word referred to by PC to IR 12

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment PC 13

CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 14

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – 110 is the op code for IfNegGoTo 15

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – Check value in data register 16

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – DR value is -1 17

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – Copy rightmost 5 bits of IR to PC 18

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – execution is complete 19

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR 20

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR 21

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment PC 22

CopyFrom IfNegGoTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 23

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – 000 is op code for CopyFrom 24

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 25

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – copy value to DR. Execution complete. 26

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR. 27

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR. 28

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment PC 29

CopyFrom IfNegGoTo CopyFrom Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 30

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – 011 is Subtract 31

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – data register is first operand 32

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – word at is second operand 34

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – word at is second operand 35

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction: (6 10 – 1 10 ) = 5 10 =

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction: 5 10 = Result is stored in DR. 38

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR. 39

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR. 40

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment PC 41

CopyFrom IfNegGoTo CopyFrom Subtract Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 42

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – 001 is CopyTo 43

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – is target location 44

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – value in DR copied to memory 45

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR 46

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 1. Copy word referred to by PC to IR 47

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 2. Increment PC 48

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction 49

CopyFrom IfNegGoTo CopyFrom Subtract CopyTo Stop Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit 3. Decode and execute instruction – 111 is op code for Stop 50

Main MemoryCPU Instruction Register Program Counter Data Register Input UnitOutput Unit Stored Program Concept: Instructions & data together in main memory 50 Instructions Data  CPU “knows” difference based only on execution process

public static void main( String[] args ) { Random generator = new Random( ); Scanner keyboard = new Scanner( System.in ); int value = keyboard.nextInt(); String text = keyboard.next(); value += generator.nextInt( 100 ); System.out.println( text + ": " + value ); }  Java executes instructions one-at-a-time in order  relates to fetch-execute cycle  Each Java instruction may be multiple ML instructions

Possible Overflow  Using our 1-byte word limit and sign magnitude, add the numbers:

Possible Overflow  Using our 1-byte word limit and sign magnitude, add the numbers: = = =

Possible Overflow  Using our 1-byte word limit and sign magnitude, add the numbers: = = = sign bit (indicating negative)

Possible Overflow  Using our 1-byte word limit and sign magnitude, add the numbers:  So computer would report -1 as the answer!  Overflow: too few bits to represent the result = = =