CSC 220: Computer Organization Unit 12 CPU programming

Similar documents
More advanced CPUs. August 4, Howard Huang 1

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

Lecture1: introduction. Outline: History overview Central processing unite Register set Special purpose address registers Datapath Control unit

CHAPTER 4: Register Transfer Language and Microoperations

REGISTER TRANSFER AND MICROOPERATIONS

REGISTER TRANSFER AND MICROOPERATIONS

Chapter 10 Computer Design Basics

Universiteit Leiden Opleiding Informatica

CHAPTER 8: Central Processing Unit (CPU)

C.P.U Organization. Memory Unit. Central Processing Unit (C.P.U) Input-Output Processor (IOP) Figure (1) Digital Computer Block Diagram

Combinational and sequential circuits (learned in Chapters 1 and 2) can be used to create simple digital systems.

Register Transfer and Micro-operations

For Example: P: LOAD 5 R0. The command given here is used to load a data 5 to the register R0.

TABLE 8-1. Control Signals for Binary Multiplier. Load. MUL0 Q 0 CAQ sr CAQ. Shift_dec. C out. Load LOADQ. CAQ sr CAQ. Shift_dec P P 1.

Lecture 04: Machine Instructions

Digital System Design Using Verilog. - Processing Unit Design

Controller Implementation--Part II

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

Hardware Level Organization

Microcontroller Systems

CSC 101: Lab Manual#9 Machine Language and the CPU (largely based on the work of Prof. William Turkett) Lab due date: 5:00pm, day after lab session

CS 2461: Computer Architecture I

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 2, 2016

Instruction Set Architecture

378: Machine Organization and Assembly Language

CpE242 Computer Architecture and Engineering Designing a Single Cycle Datapath

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

Computer Architecture 2/26/01 Lecture #

Chapter 4. MARIE: An Introduction to a Simple Computer. Chapter 4 Objectives. 4.1 Introduction. 4.2 CPU Basics

MICROPROGRAMMED CONTROL

ECE 2300 Digital Logic & Computer Organization. More Single Cycle Microprocessor

Chapter 5. Computer Architecture Organization and Design. Computer System Architecture Database Lab, SANGJI University

COSC 122 Computer Fluency. Computer Organization. Dr. Ramon Lawrence University of British Columbia Okanagan

There are four registers involved in the fetch cycle: MAR, MBR, PC, and IR.

8-1. Fig. 8-1 ASM Chart Elements 2001 Prentice Hall, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 2e, Updated.

8-1. Fig. 8-1 ASM Chart Elements 2001 Prentice Hall, Inc. M. Morris Mano & Charles R. Kime LOGIC AND COMPUTER DESIGN FUNDAMENTALS, 2e, Updated.

Computer Architecture

THE MICROPROCESSOR Von Neumann s Architecture Model

Computer Organization (Autonomous)

Class Notes. Dr.C.N.Zhang. Department of Computer Science. University of Regina. Regina, SK, Canada, S4S 0A2

Outcomes. Lecture 13 - Introduction to the Central Processing Unit (CPU) Central Processing UNIT (CPU) or Processor

Module 5 - CPU Design

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE251: Tuesday Aug. 29


Wednesday, September 13, Chapter 4

Materials: 1. Projectable Version of Diagrams 2. MIPS Simulation 3. Code for Lab 5 - part 1 to demonstrate using microprogramming

CS 31: Intro to Systems Digital Logic. Kevin Webb Swarthmore College February 3, 2015

COMPUTER ARCHITECTURE AND ORGANIZATION Register Transfer and Micro-operations 1. Introduction A digital system is an interconnection of digital

Multicycle conclusion

STRUCTURE OF DESKTOP COMPUTERS

COSC121: Computer Systems: Review

CS 101, Mock Computer Architecture

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

REGISTER TRANSFER LANGUAGE

ECE260: Fundamentals of Computer Engineering

COMPUTER ORGANIZATION

COMPUTER ORGANIZATION AND ARCHITECTURE

Arithmetic-logic units

Chapter 2 Instruction Set Architecture

Information Science 1

COSC121: Computer Systems: Review

CPE300: Digital System Architecture and Design

361 datapath.1. Computer Architecture EECS 361 Lecture 8: Designing a Single Cycle Datapath

Information Science 1

Chapter 9 Computer Design Basics

Many ways to build logic out of MOSFETs

Wednesday, February 4, Chapter 4

Chapter 3 : Control Unit

A3 Computer Architecture

CSC 252: Computer Organization Spring 2018: Lecture 11

UNIT - V MEMORY P.VIDYA SAGAR ( ASSOCIATE PROFESSOR) Department of Electronics and Communication Engineering, VBIT

LC-3 Instruction Set Architecture. Textbook Chapter 5

Computer Organization and Design

Processing Unit CS206T

EC-801 Advanced Computer Architecture

Topic Notes: MIPS Instruction Set Architecture

COMPUTER ARCHITECTURE AND PARALEL PROCESSING STUDY NOTES

Introduction. Datapath Basics

Objective now How are such control statements registers and other components Managed to ensure proper execution of each instruction

Chapter 5 The LC-3. ACKNOWLEDGEMENT: This lecture uses slides prepared by Gregory T. Byrd, North Carolina State University 5-2

10/24/2016. We Can Perform Any Computation with an FSM. ECE 120: Introduction to Computing. Find the Minimum Value Among Ten Integers

CPU Design John D. Carpinelli, All Rights Reserved 1

Topics. Computer Organization CS Exam 2 Review. Infix Notation. Reverse Polish Notation (RPN)

EEL 5722C Field-Programmable Gate Array Design

CS311 Lecture: CPU Implementation: The Register Transfer Level, the Register Set, Data Paths, and the ALU

Computer Organization. Structure of a Computer. Registers. Register Transfer. Register Files. Memories

EECS150. Implement of Processor FSMs

Computer Organization II CMSC 3833 Lecture 33

Block diagram view. Datapath = functional units + registers

Memory General R0 Registers R1 R2. Input Register 1. Input Register 2. Program Counter. Instruction Register

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 4. MARIE: An Introduction to a Simple Computer

MICROPROGRAMMED CONTROL:-

Outline. EEL-4713 Computer Architecture Designing a Single Cycle Datapath

CS1101: Lecture 34. The ISA Level. Instruction Sets. Lecture Outline. Introduction. Data Movement Instructions. Instruction Types

EE 3170 Microcontroller Applications

CHAPTER 5 A Closer Look at Instruction Set Architectures

Picture of memory. Word FFFFFFFD FFFFFFFE FFFFFFFF

Transcription:

College of Computer and Information Sciences Department of Computer Science CSC 220: Computer Organization Unit 12 CPU programming 1

Instruction set architectures Last time we built a simple, but complete, datapath. The datapath is ultimately controlled by a programmer, so today we ll look at several aspects of this programming in more detail. How programs are executed on processors An introduction to instruction set architectures Example instructions and programs Next, we ll see how programs are encoded in a processor. Following that, we ll finish our processor by designing a control unit, which converts our programs into signals for the datapath. 2

Programming and CPUs 3

Control units From these examples, you can see that different actions are performed when we provide different inputs for the datapath control signals. The second question we had was Who exactly decides which registers are read and written and which ALU function is executed? In real computers, the datapath actions are determined by the program that s loaded and running. A control unit is responsible for generating the correct control signals for a datapath, based on the program code. We ll talk about programs and control units next week. 4

Programming and CPUs Programs written in a high-level language like C++ must be compiled to produce an executable program. The result is a CPU-specific machine language program. This can be loaded into memory and executed by the processor. CS231 focuses on stuff below the dotted blue line, but machine language serves as the interface between hardware and software. High-level program Compiler Executable file Control Unit Control words Software Hardware Datapath 5

6

7

Memory While memory transfers are similar to register transfers, we usually identify them differently. Specifically, memory to register transfers are called read operations, while register to memory transfers are called write operations. Both require specification of the memory location to be used (which can be done through a special register or a special bus) and a storage location which will hold the result of a read or which holds the data to be written. 8

RTL expressions for a Read operation, assuming the use of an address registers: RTL expressions for a Write operation, assuming use of a data register: 9

Register to Memory Transfers are denoted using square brackets surrounding the memory address. e.g. DR M[AR] (Read operation) e.g. M[AR] DR (Write operation) 10

Examples of Arithmetic Microoperations Examples of Logic Microoperations 11

Assembly and machine languages Machine language instructions are sequences of bits in a specific order. To make things simpler, people typically use assembly language. We assign mnemonic names to operations and operands. There is (almost) a one-to-one correspondence between these mnemonics and machine instructions, so it is very easy to convert assembly programs to machine language. We ll use assembly code this today to introduce the basic ideas, and switch to machine language next time. 12

Data manipulation instructions Data manipulation instructions correspond to ALU operations. For example, here is a possible addition instruction, and its equivalent using our register transfer notation: operation operands Register transfer instruction: ADD R0, R1, R2 R0 R1 + R2 destination sources This is similar to a high-level programming statement like R0 = R1 + R2 Here, all of the operands are registers. 13

More data manipulation instructions Here are some other kinds of data manipulation instructions. NOT R0, R1 R0 R1 ADD R3, R3, #1 R3 R3 + 1 SUB R1, R2, #5 R1 R2-5 Some instructions, like the NOT, have only one operand. In addition to register operands, constant operands like 1 and 5 are also possible. Constants are denoted with a hash mark in front. 14

Relation to the datapath These instructions reflect the design of our datapath from last week. There are at most two source operands in each instruction, since our ALU has just two inputs. The two sources can be two registers, or one register and one constant. More complex operations like WR DA AA Constant D data Write D address Register File A address B address A data MB B data BA R0 R1 + R2-3 S D1 D0 Q must be broken down into several lowerlevel instructions. Instructions have just one destination operand, which must be a register. V C N Z A ALU F B 15

What about RAM? Recall that our ALU has direct access only to the register file. RAM contents must be copied to the registers before they can be used as ALU operands. Similarly, ALU results must go through the registers before they can be stored into memory. We rely on data movement instructions to transfer data between the RAM and the register file. WR DA AA Constant D data Write D address Register File A address B address V C N Z A data A MB B data S D1 D0 Q ALU F B BA +5V MW RAM ADRS DATA OUT CS WR D0 Q D1 S MD 16

Loading a register from RAM A load instruction copies data from a RAM address to one of the registers. WR DA D data Write D address LD R1,(R3) R1 M[R3] AA Register File A address B address BA Remember in our datapath, the RAM address must come from one of the registers in the example above, R3. The parentheses help show which register operand holds the memory address. Constant A data A MB B data S D1 D0 Q B +5V MW RAM ADRS DATA OUT CS WR V C N Z ALU F Q D1 D0 S MD 17

Storing a register to RAM A store instruction copies data from a register to an address in RAM. WR DA Write D address D data ST (R3),R1 M[R3] R1 AA Register File A address B address BA One register specifies the RAM address to write to in the example above, R3. The other operand specifies the actual data to be stored into RAM R1 above. Constant A data A MB B data S D1 D0 Q B +5V MW ADRS DATA CS WR RAM OUT V C N Z ALU F D0 Q D1 S MD 18

Loading a register with a constant With our datapath, it s also possible to load a constant into the register file: WR DA D data Write D address LD R1, #0 R1 0 AA Register File A address B address BA Our example ALU has a transfer B operation (=10000) which lets us pass a constant up to the register file. This gives us an easy way to initialize registers. Constant A data A MB B data S D1 D0 Q B +5V MW RAM ADRS DATA OUT CS WR V C N Z ALU F D0 Q D1 S MD 19

Storing a constant to RAM And you can store a constant value directly to RAM too: WR Write D data ST (R3), #0 M[R3] 0 DA D address Register File This provides an easy way to initialize memory contents. AA A address B address A data B data BA Constant MB S D1 D0 Q RAM A B +5V MW ADRS DATA CS WR OUT V C N Z ALU F D0 Q D1 S MD 20

The # and ( ) are important! We ve seen several statements containing the # or ( ) symbols. These are ways of specifying different addressing modes. The addressing mode we use determines which data are actually used as operands: LD R0, #1000 // R0 1000 LD R0, 1000 // R0 M[1000] LD R3, R0 LD R3, (R0) // R3 R0 // R3 M[R0] The design of our datapath determines which addressing modes we can use. The second example above wouldn t work in our datapath. Why not? We ll talk about addressing modes in more detail next lecture. 21

A small example Here s an example register-transfer operation. M[1000] M[1000] + 1 This is the assembly-language equivalent: LD R0, #1000 // R0 1000 LD R3, (R0) // R3 M[1000] ADD R3, R3, #1 // R3 R3 + 1 ST (R0), R3 // M[1000] R3 An awful lot of assembly instructions are needed! For instance, we have to load the memory address 1000 into a register first, and then use that register to access the RAM. This is due to our relatively simple datapath design, which only allows register and constant operands to the ALU. Later on, mostly in CS232, you ll see why this can be a good thing. 22

Control flow instructions Programs consist of a lot of sequential instructions, which are meant to be executed one after another. Thus, programs are stored in memory so that: Each program instruction occupies one address. Instructions are stored one after another. 768: LD R0, #1000 // R0 1000 769: LD R3, (R0) // R3 M[1000] 770: ADD R3, R3, #1 // R3 R3 + 1 771: ST (R0), R3 // M[1000] R3 A program counter (PC) keeps track of the current instruction address. Ordinarily, the PC just increments after executing each instruction. But sometimes we need to change this normal sequential behavior, with special control flow instructions. 23

Instruction encoding We ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers use instruction sets to issue commands. Now let s complete our processor with a control unit that converts assembly language instructions into datapath signals. Today we ll see how control units fit into the big picture, and how assembly instructions can be represented in a binary format. On Wednesday we ll show all of the implementation details for our sample datapath and assembly language. 24

note Machine language is the interface between software and processors. High-level programs must be translated into machine language before they can be run. There are three main categories of instructions. Data manipulation operations, such as adding or shifting Data transfer operations to copy data between registers and RAM Control flow instructions to change the execution order Instruction set architectures depend highly on the host CPU s design. Today we saw instructions that would be appropriate for our datapath from last week. On Monday we ll look at some other possibilities. 25

Instruction encoding We ve already seen some important aspects of processor design. A datapath contains an ALU, registers and memory. Programmers and compilers use instruction sets to issue commands. Now let s complete our processor with a control unit that converts assembly language instructions into datapath signals. Today we ll see how control units fit into the big picture, and how assembly instructions can be represented in a binary format. On Wednesday we ll show all of the implementation details for our sample datapath and assembly language. 26

Review: Datapath Recall that our ALU has direct access only to the register file. RAM contents must be copied to the registers before they can be used as ALU operands. Similarly, ALU results must go through the registers before they can be stored into memory. We rely on data movement instructions to transfer data between the RAM and the register file. WR DA AA Constant D data Write D address Register File A address B address V C N Z A data A MB B data S D1 D0 Q ALU F B BA +5V MW RAM ADRS DATA OUT CS WR D0 Q D1 S MD 27

Block diagram of a processor Program Control Unit Control signals Status signals Datapath The control unit connects programs with the datapath. It converts program instructions into control words for the datapath, including signals WR, DA, AA, BA, MB,, MW, MD. It executes program instructions in the correct sequence. It generates the constant input for the datapath. The datapath also sends information back to the control unit. For instance, the ALU status bits V, C, N, Z can be inspected by branch instructions to alter a program s control flow. 28

Register format ALU operations ADD R1, R2, R3 All register format ALU operations need the same values for the following control signals: MB = 0, because all operands come from the register file. MD = 0 and WR = 1, to save the ALU result back into a register. MW = 0 since RAM is not modified. WR 1 DA AA constant V C N Z D Register file A A ALU G B B 1 0 Mux B BA MB 0 MW 0 ADRS DATA Data RAM OUT 0 1 Mux D MD 0 29

Memory write operations ST (R0), R1 All memory write operations need the same values for the following control signals: MB = 0, because the data to write comes from the register file. MD = X and WR = 0, since none of the registers are changed. MW = 1, to update RAM. WR 0 DA AA constant V C N Z D Register file A A ALU G B B 1 0 Mux B BA MB 0 MW 1 ADRS DATA Data RAM OUT 0 1 Mux D MD X 30