Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Similar documents
Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

CPU Performance Pipelined CPU

The MIPS Instruction Set Architecture

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

EE108B Lecture 3. MIPS Assembly Language II

Computer Architecture. The Language of the Machine

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Reduced Instruction Set Computer (RISC)

CS 4200/5200 Computer Architecture I

M2 Instruction Set Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Computer Architecture. MIPS Instruction Set Architecture

Instructions: Language of the Computer

Course Administration

Reduced Instruction Set Computer (RISC)

RISC, CISC, and ISA Variations

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

MIPS Instruction Set

Laboratory Exercise 6 Pipelined Processors 0.0

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

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

Computer Organization MIPS ISA

INSTRUCTION SET COMPARISONS

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Mips Code Examples Peter Rounce

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

Reminder: tutorials start next week!

MIPS Assembly Language. Today s Lecture

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Instruction Set Principles. (Appendix B)

Unsigned Binary Integers

Unsigned Binary Integers

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

MIPS Reference Guide

Lecture 4: Instruction Set Architecture

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Review of instruction set architectures

MIPS%Assembly% E155%

Examples of branch instructions

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

EE 109 Unit 8 MIPS Instruction Set

MIPS Instruction Format

F. Appendix 6 MIPS Instruction Reference

Chapter 2A Instructions: Language of the Computer

Concocting an Instruction Set

Project Part A: Single Cycle Processor

Midterm. Sticker winners: if you got >= 50 / 67

Processor design - MIPS

Programmable Machines

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

Flow of Control -- Conditional branch instructions

CPS311 - COMPUTER ORGANIZATION. A bit of history

Lectures 3-4: MIPS instructions

Programmable Machines

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Exam in Computer Engineering

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

ISA: The Hardware Software Interface

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

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

MIPS Instruction Reference

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

Hakim Weatherspoon CS 3410 Computer Science Cornell University

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

ECE260: Fundamentals of Computer Engineering

Computer Organization and Components

ECE 154A Introduction to. Fall 2012

Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University. See P&H Appendix , and 2.21

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

CENG3420 Lecture 03 Review

CS 351 Exam 2 Mon. 11/2/2015

are Softw Instruction Set Architecture Microarchitecture are rdw

Computer Architecture Experiment

Chapter 4. The Processor. Computer Architecture and IC Design Lab

MACHINE LANGUAGE. To work with the machine, we need a translator.

ECE260: Fundamentals of Computer Engineering

CS 61c: Great Ideas in Computer Architecture

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Instructions: Language of the Computer

CS61CL Machine Structures. Lec 5 Instruction Set Architecture

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

RTL Model of a Two-Stage MIPS Processor

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Concocting an Instruction Set

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

Transcription:

Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, and Sirer. See P&H Chapter: 2.16-2.20, 4.1-4.4, Appendix B

Understanding the basics of a processor We now have the technology to build a CPU! Putting it all together: Arithmetic Logic Unit (ALU) Lab0 & 1, Lecture 2 & 3 Register File Lecture 4 and 5 ory Lecture 5 SRAM: cache DRAM: main memory MIPS Instructions & how they are executed 2

MIPS register file 32 x 32-bit registers r0 wired to zero Write port indexed via R W on falling edge when WE=1 Read ports indexed via R A, R B Registers 32 W r1 r2 r31 A B 32 32 Numbered from 0 to 31. WE Can be referred by number: $0, $1, $2, $31 Convention, each register also has a name: R W R A R B 1 5 5 5 $16 - $23 à $s0 - $s7, $8 - $15 à $t0 - $t7 [P&H p105] 3

32-bit address 32-bit data (but byte addressed) Enable + 2 bit memory control (mc) 00: read word (4 byte aligned) 01: write byte D in memory 32 32 32 addr 2 mc 10: write halfword (2 byte aligned) 11: write word (4 byte aligned) E D out 1 byte address 0x05 0xffffffff... 0x0000000b 0x0000000a 0x00000009 0x00000008 0x00000007 0x00000006 0x00000005 0x00000004 0x00000003 0x00000002 0x00000001 0x00000000 4

A MIPS CPU with a (modified) Harvard architecture Modified: insns & data in common addr space Not von Neumann: ours access insn & data in parallel Registers ALU CPU Control data, address, control 10100010000 10110000011 00100010101... 00100000001 00100000010 00010000100... Data ory Program ory 5

Prog inst PC +4 Instructions: Reg. File 00100000000000100000000000001010 00100000000000010000000000000000 00000000001000100001100000101010 5 5 5 control stored in memory, encoded in binary ALU A basic processor fetches decodes executes Data one instruction at a time 6

for (i = 0; i < 10; i++) printf( go cucs ); High Level Language C, Java, Python, Ruby, Loops, control flow, variables main: addi r2, r0, 10 addi r1, r0, 0 loop: slt r3, r1, r2... op=addi r0 r2 10 00100000000000100000000000001010 00100000000000010000000000000000 00000000001000100001100000101010 ALU, Control, Register File, Assembly Language No symbols (except labels) One operation per statement human readable machine language Machine Language Binary-encoded assembly Labels become addresses The language of the CPU Instruction Set Architecture Machine Implementation (Microarchitecture) 7

Different CPU architectures specify different instructions Two classes of ISAs Reduced Instruction Set Computers (RISC) IBM Power PC, Sun Sparc, MIPS, Alpha Complex Instruction Set Computers (CISC) Intel x86, PDP-11, VAX Another ISA classification: Load/Store Architecture Data must be in registers to be operated on For example: array[x] = array[y] + array[z] 1 add? OR 2 loads, an add, and a store? Keeps HW simple à many RISC ISAs are load/store 8

MIPS (RISC) ISA of 3410 200 instructions, 32 bits each, 3 formats mostly orthogonal all operands in registers almost all are 32 bits each, can be used interchangeably 1 addressing mode: [reg + imm] 100 Main St. x86 (CISC) ISA of your desktop & laptop > 1000 instructions, 1 to 15 bytes each operands in special registers, general purpose registers, memory, on stack, can be 1, 2, 4, 8 bytes, signed or unsigned 10s of addressing modes e.g. [segment + reg + reg*scale + offset] Blue house half a mile past the oak tree across from the gas station. 9

Prog. PC +4 inst Reg. File 5 5 5 control ALU Data Fetch Decode Execute ory WB A Single cycle processor this diagram is not 100% spatial 10

Basic CPU execution loop 1. Instruction Fetch 2. Instruction Decode 3. Execution (ALU) 4. ory Access 5. Register Writeback 11

Prog. PC +4 inst Reg. File 5 5 5 control ALU Data Fetch Decode Execute ory WB Fetch 32-bit instruction from memory Increment PC = PC + 4 12

Prog. PC +4 inst Reg. File 5 5 5 control ALU Data Fetch Decode Execute ory WB Gather data from the instruction Read opcode; determine instruction type, field lengths Read in data from register file (0, 1, or 2 reads for jump, addi, or add, respectively) 13

Prog. PC +4 inst Reg. File 5 5 5 control ALU Data Fetch Decode Execute ory WB Useful work done here (+, -, *, /), shift, logic operation, comparison (slt) Load/Store? lw $t2, 32($t3) à Compute address 14

Prog. PC +4 inst Reg. File 5 5 5 control ALU addr Data Data R/W Data Fetch Decode Execute ory WB Used by load and store instructions only Other instructions will skip this stage 15

Prog. PC +4 inst Reg. File 5 5 5 control ALU Data Fetch Decode Execute ory WB Write to register file For arithmetic ops, logic, shift, etc, load. What about stores? Update PC For branches, jumps 16

Arithmetic/Logical R-type: result and two source registers, shift amount I-type: 16-bit immediate with sign/zero extension ory Access I-type load/store between registers and memory word, half-word and byte operations Control flow J-type conditional branches: pc-relative addresses jumps: fixed offsets, register absolute 17

00000001000001100010000000100110 op rs rt rd - func 6 5 5 5 5 6 bits op func mnemonic description 0x0 0x21 ADDU rd, rs, rt R[rd] = R[rs] + R[rt] 0x0 0x23 SUBU rd, rs, rt R[rd] = R[rs] R[rt] 0x0 0x25 OR rd, rs, rt R[rd] = R[rs] R[rt] 0x0 0x26 XOR rd, rs, rt R[rd] = R[rs] R[rt] 0x0 0x27 NOR rd, rs rt R[rd] = ~ ( R[rs] R[rt] ) example: r4 = r8 r6 # XOR r4, r8, r6 rd, rs, rt 18

XOR r4 r8 r6 Prog. Reg. File ALU r8 r6 PC +4 5 5 5 control Fetch Decode Execute ory WB skip Example: r4 = r8 r6 # XOR r4, r8, r6 19

00000000000001000100000110000000 op - rt rd shamt func 6 5 5 5 5 6 bits op func mnemonic description 0x0 0x0 SLL rd, rt, shamt R[rd] = R[rt] << shamt 0x0 0x2 SRL rd, rt, shamt R[rd] = R[rt] >>> shamt (zero ext.) 0x0 0x3 SRA rd, rt, shamt R[rd] = R[rt] >> shamt (sign ext.) example: r8 = r4 * 64 # SLL r8, r4, 6 r8 = r4 << 6 20

SLL r8 r4 6 Prog. Reg. File ALU r4 << 6 PC +4 5 5 5 control Fetch Decode Execute ory WB Example: r8 = r4 * 64 # SLL r8, r4, 6 r8 = r4 << 6 skip 21

00100100101001010000000000000101 op rs rd immediate 6 5 5 16 bits op mnemonic description 0x9 ADDIU rd, rs, imm R[rd] = R[rs] + sign_extend(imm) 0xc ANDI rd, rs, imm R[rd] = R[rs] & zero_extend(imm) 0xd ORI rd, rs, imm R[rd] = R[rs] zero_extend(imm) example: r5 = r5 + 5 # ADDIU r5, r5, 5 r5 += 5 What if immediate is negative? r5 += -1 r5 += 65535 22

ADDIU r5 r5 5 Prog. PC +4 Reg. File 5 5 5 control ALU r5 + 5 imm shamt extend 16 32 Example: r5 = r5 + 5 # ADDIU r5, r5, 5 Fetch Decode Execute ory WB skip 23

00111100000001010000000000000101 op - rd immediate 6 5 5 16 bits op mnemonic description 0xF LUI rd, imm R[rd] = imm << 16 example: r5 = 0x50000 # LUI r5, 5 Example: LUI r5, 0xdead ORI r5, r5 0xbeef What does r5 =? 24

LUI r5 5 Prog. PC +4 Reg. File 5 5 5 control ALU 16 0x50000 imm extend shamt Example: r5 = 0x50000 # LUI r5, 5 Fetch Decode Execute ory WB skip 25

Arithmetic/Logical R-type: result and two source registers, shift amount I-type: 16-bit immediate with sign/zero extension ory Access I-type load/store between registers and memory word, half-word and byte operations Control flow J-type conditional branches: pc-relative addresses jumps: fixed offsets, register absolute 26

# r5 contains 5 (0x00000005) SB r5, 0(r0) SB r5, 2(r0) SW r5, 8(r0) Two ways to store a word in memory. 0xffffffff... 0x0000000b 0x0000000a 0x00000009 0x00000008 0x00000007 0x00000006 0x00000005 0x00000004 0x00000003 0x00000002 0x00000001 0x00000000 27

Endianness: Ordering of bytes within a memory word Little Endian = least significant part first (MIPS, x86) as 4 bytes as 2 halfwords 1000 1001 1002 1003 as 1 word 0x12345678 Big Endian = most significant part first (MIPS, networks) as 4 bytes as 2 halfwords 1000 1001 1002 1003 as 1 word 0x12345678 28

# r5 contains 5 (0x00000005) SB r5, 2(r0) LB r6, 2(r0) 0xffffffff... 0x0000000b 0x0000000a 0x00000009 0x00000008 0x00000007 0x00000006 SW r5, 8(r0) LB r7, 8(r0) LB r8, 11(r0) 0x00000005 0x00000004 0x00000003 0x00000002 0x00000001 0x00000000 30

10101100101000010000000000000100 op rs rd offset 6 5 5 16 bits op mnemonic description base + offset addressing 0x23 LW rd, offset(rs) R[rd] = [offset+r[rs]] 0x2b SW rd, offset(rs) [offset+r[rs]] = R[rd] signed offsets Example: = [4+r5] = r1 # SW r1, 4(r5) 32

SW r1 r5 4 Prog. Reg. File ALU r5+4 PC +4 imm 5 5 5 control ext addr Data Write Enable Example: = [4+r5] = r1 # SW r1, 4(r5) 33

10101100101000010000000000000100 op rs rd offset 6 5 5 16 bits op mnemonic description 0x20 LB rd, offset(rs) R[rd] = sign_ext([offset+r[rs]]) 0x24 LBU rd, offset(rs) R[rd] = zero_ext([offset+r[rs]]) 0x21 LH rd, offset(rs) R[rd] = sign_ext([offset+r[rs]]) 0x25 LHU rd, offset(rs) R[rd] = zero_ext([offset+r[rs]]) 0x23 LW rd, offset(rs) R[rd] = [offset+r[rs]] 0x28 SB rd, offset(rs) [offset+r[rs]] = R[rd] 0x29 SH rd, offset(rs) [offset+r[rs]] = R[rd] 0x2b SW rd, offset(rs) [offset+r[rs]] = R[rd] 34

Arithmetic/Logical R-type: result and two source registers, shift amount I-type: 16-bit immediate with sign/zero extension ory Access I-type load/store between registers and memory word, half-word and byte operations Control flow J-type: fixed offset jumps, jump-and-link R-type: register absolute jumps I-type: conditional branches: pc-relative addresses 35

00001001000000000000000000000001 op immediate 6 26 bits op Mnemonic Description = concatenate 0x2 J target PC = (PC+4) 31..28 target 00 (PC+4) 31..28 target 00 4 bits 26 bits 2 bits (PC+4) 31..28 01000000000000000000000001 00 MIPS Quirk: jump targets computed using already incremented PC 36

Prog. Reg. File ALU PC +4 target (PC+4) 31..28 0x4000004 5 5 5 control imm ext (PC+4) 31..28 0x100000100 J addr Data Example: PC = (PC+4) 31..28 target 00 # J 0x1000001 37

00000000011000000000000000001000 op rs - - - func 6 5 5 5 5 6 bits op func mnemonic description 0x0 0x08 JR rs PC = R[rs] Example: JR r3 38

Prog. inst Reg. File R[r3] ALU PC +4 tgt 5 5 5 control imm JR ext addr Data ex: JR r3 op func mnemonic description 0x0 0x08 JR rs PC = R[rs] 39

E.g. Use Jump or Jump Register instruction to jump to 0xabcd1234 But, what about a jump based on a condition? # assume 0 <= r3 <= 1 if (r3 == 0) jump to 0xdecafe00 else jump to 0xabcd1234 40

00010000101000010000000000000011 op rs rd offset 6 5 5 16 bits signed op mnemonic description 0x4 BEQ rs, rd, offset if R[rs] == R[rd] then PC = PC+4 + (offset<<2) 0x5 BNE rs, rd, offset if R[rs]!= R[rd] then PC = PC+4 + (offset<<2) Example: BEQ r5, r1, 3 if(r[r5]==r[r1]) PC = PC+4 + 12 (i.e. 12 == 3<<2) A word about all these + s 41

Prog. inst Reg. File R[r5] R[r1] ALU PC +4 (PC+4)+3<<2 offset + tgt 5 5 5 control imm =? BEQ ext addr Data ex: BEQ r5, r1, 3 op mnemonic description 0x4 BEQ rs, rd, offset if R[rs] == R[rd] then PC = PC+4 + (offset<<2) 42

00000100101000010000000000000010 op rs subop offset 6 bits 5 bits 5 bits 16 bits op subop mnemonic description signed 0x1 0x0 BLTZ rs, offset if R[rs] < 0 then PC = PC+4+ (offset<<2) 0x1 0x1 BGEZ rs, offset if R[rs] 0 then PC = PC+4+ (offset<<2) 0x6 0x0 BLEZ rs, offset if R[rs] 0 then PC = PC+4+ (offset<<2) 0x7 0x0 BGTZ rs, offset if R[rs] > 0 then PC = PC+4+ (offset<<2) Example: BGEZ r5, 2 if(r[r5] 0) PC = PC+4 + 8 (i.e. 8 == 2<<2) 43

Prog. inst Reg. File R[r5] ALU PC +4 (PC+4)+2<<2 offset + tgt ex: BGEZ r5, 2 5 5 5 control imm BEQZ =? cmp ext addr Data op subop mnemonic description 0x1 0x1 BGEZ rs, offset if R[rs] 0 then PC = PC+4+ (offset<<2) 44

00001101000000000000000000000001 op immediate 6 bits 26 bits op mnemonic description 0x3 JAL target Discuss later r31 = PC+8 (+8 due to branch delay slot) PC = (PC+4) 31..28 target 00 Why? Function/procedure calls 45

Prog. PC +4 inst PC+8 +4 offset + tgt Reg. File 5 5 5 control imm ex: JAL 0x1000001 R[r31] =? cmp ext op mnemonic description ALU Could have used ALU for link add addr Data r31 = PC+8 PC = (PC+4) 31..28 0x4000004 0x3 JAL target r31 = PC+8 (+8 due to branch delay slot) PC = (PC+4) 31..28 (target << 2) 46

Arithmetic/Logical R-type: result and two source registers, shift amount I-type: 16-bit immediate with sign/zero extension ory Access I-type load/store between registers and memory word, half-word and byte operations Control flow J-type conditional branches: pc-relative addresses jumps: fixed offsets, register absolute Many other instructions possible: vector add/sub/mul/div, string operations manipulate coprocessor I/O 47

We have all that it takes to build a processor! Arithmetic Logic Unit (ALU) Lab0 & 1, Lecture 2 & 3 Register File Lecture 4 and 5 ory Lecture 5 MIPS processor and ISA is an example of a Reduced Instruction Set Computers (RISC). Simplicity is key, thus enabling us to build it! We now know the data path for the MIPS ISA: register, memory and control instructions 48