CS152 Computer Architecture and Engineering. Lecture 1 CS 152 Introduction & MIPS Review John Lazzaro. Dave Patterson

Similar documents
CS152 Computer Architecture and Engineering. Lecture 1 Introduction & MIPS Review Dave Patterson. www-inst.eecs.berkeley.

Computer Organization & Design

Digital System Design II

Computer Architecture. The Language of the Machine

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

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

The MIPS Instruction Set Architecture

MIPS Instruction Set

MIPS Reference Guide

Lecture 3 MIPS ISA and Performance

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Computer Architecture. MIPS Instruction Set Architecture

F. Appendix 6 MIPS Instruction Reference

software hardware Which is easier to change/design???

MIPS Assembly Language. Today s Lecture

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

Review: Organization. CS152 Computer Architecture and Engineering Lecture 2. Review of MIPS ISA and Design Concepts

MIPS Instruction Reference

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

MIPS Instruction Format

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

EE108B Lecture 3. MIPS Assembly Language II

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

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

CS61CL Machine Structures. Lec 5 Instruction Set Architecture

CS 351 Exam 2 Mon. 11/2/2015

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

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

CS 4200/5200 Computer Architecture I

M2 Instruction Set Architecture

ECE Exam I February 19 th, :00 pm 4:25pm

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

UCB CS61C : Machine Structures

CS61C : Machine Structures

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

Q1: /30 Q2: /25 Q3: /45. Total: /100

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

CS 61c: Great Ideas in Computer Architecture

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

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

CMPE324 Computer Architecture Lecture 2

Midterm Questions Overview

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

MIPS Assembly Programming

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

Instructions: Language of the Computer

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

Final Project: MIPS-like Microprocessor

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

ECE 473 Computer Architecture and Organization Project: Design of a Five Stage Pipelined MIPS-like Processor Project Team TWO Objectives

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

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

Computer Architecture

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

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

Assembly Programming

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

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

Instruction Set Principles. (Appendix B)

Programming the processor

SPIM Instruction Set

Concocting an Instruction Set

Programmable Machines

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

ECE331: Hardware Organization and Design

Computer Architecture = Instruction Set Architecture + Machine Organization +.. Overview

MIPS%Assembly% E155%

EEC170 Computer Architecture. Lecture 1: Introduction to Computer Architecture

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

Programmable Machines

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

INSTRUCTION SET COMPARISONS

CS 61c: Great Ideas in Computer Architecture

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

ECE260: Fundamentals of Computer Engineering

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

ECE260: Fundamentals of Computer Engineering

CPS311 - COMPUTER ORGANIZATION. A bit of history

TSK3000A - Generic Instructions

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

Week 10: Assembly Programming

CS654 Advanced Computer Architecture. Lec 1 - Introduction

Midterm Questions Overview

CS3350B Computer Architecture

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

CSc 256 Midterm 2 Fall 2011

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

EE 109 Unit 8 MIPS Instruction Set

RTL Model of a Two-Stage MIPS Processor

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

Transcription:

CS152 Computer Architecture and Engineering Lecture 1 CS 152 Introduction & MIPS Review 2004-08-31 John Lazzaro (www.cs.berkeley.edu/~lazzaro) Dave Patterson (www.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs152/ CS 152 L01 Introduction & MIPS Review (1)

Where is Computer Architecture and Engineering? Application (Netscape) Software Hardware Compiler Assembler Processor Memory Operating System (Windows 2K) Datapath & Control I/O system Instruction Set Architecture 152 Digital Design Circuit Design transistors *Coordination of many levels of abstraction CS 152 L01 Introduction & MIPS Review (2)

Anatomy: 5 components of any Computer Personal Computer Computer Processor Control ( brain ) Datapath ( brawn ) Memory (where programs, data live when running) Devices Input Output Keyboard, Mouse Disk (where programs, data live when not running) Display, Printer CS 152 L01 Introduction & MIPS Review (3)

Computer Technology - Dramatic Change! Processor 2X in speed every 1.5 years (since 85); 100X performance in last decade. Memory DRAM capacity: 2x / 2 years (since 96); 64x size improvement in last decade. Disk Capacity: 2X / 1 year (since 97) 250X size in last decade. CS 152 L01 Introduction & MIPS Review (4)

Tech. Trends: Microprocessor Complexity 2X transistors/chip Every 1.5 to 2.0 years Called Moore s Law CS 152 L01 Introduction & MIPS Review (5)

1 0 Where are we going?? Input Input Multiplicand Multiplier Single/multicycle Datapaths 32 2 Extra 2 bits 32=>34 signex 2 34 34-bit ALU 34 32 HI register (16x2 bits) LoadHI ClearHI 32 Multiplicand Register 32=>34 signex <<1 34x2 MUX 34 34 LoadMp LO register (16x2 bits) LoadLO 32 34 Arithmetic Sub/Add 2 Multi x2/x1 ShiftAll Prev LO[1] 2 LO[1:0] Booth Encoder ENC[2] ENC[1] ENC[0] "LO[0]" Control Logic 32 32 Result[HI] Result[LO] 1000 Moore s Law CPU µproc 60%/yr. (2X/1.5yr) IFetchDcd Exec Mem WB IFetchDcd Exec Mem WB IFetchDcd Exec Mem WB IFetchDcd Exec Mem WB Pipelining CS152 Fall 04 Performance 100 10 1 198 0198 198 198 3198 4198 5198 6198 7198 8198 9199 1 2 Time 0199 199 2199 3199 4199 5199 6199 7199 8199 9200 Processor-Memory Performance Gap: (grows 50% / year) DRAM 0 DRAM 9%/yr. (2X/10 yrs) Y O U R Memory Systems I/O C P U CS 152 L01 Introduction & MIPS Review (6)

Project Focus Design Intensive Class --- 100 to 150 hours per semester per student (250 before) MIPS Instruction Set ---> FPGA implementation Modern CAD System: Schematic capture and Simulation Design Description Computer-based "breadboard" Behavior over time Before construction Xilinx FPGA board Running design at 10 to 25 MHz (~ state-of-theart clock rate a decade ago) CS 152 L01 Introduction & MIPS Review (7)

Project Simulates Industrial Environment Project teams have 4 or 5 members in same discussion section Must work in groups as in the real world Communicate with colleagues (team members) Communication problems are natural What have you done? What answers you need from others? You must document your work!!! Everyone must keep an on-line notebook Communicate with supervisor (TAs) How is the team s plan? Short progress reports are required: - What is the team s game plan? - What is each member s responsibility? CS 152 L01 Introduction & MIPS Review (8)

CS152: So what's in it for me? Build a real computer! In-depth understanding of the inner-workings of computers & trade-offs at HW/SW boundary Insight into fast/slow operations that are easy/hard to implement in hardware (HW) Experience with the design process in the context of a large complex (hardware) design. Functional Spec --> Control & Datapath --> Physical implementation Modern CAD tools Make 32-bit RISC processor in actual hardware Learn to work as team, with manager (TA) Designer's "Conceptual" toolbox. CS 152 L01 Introduction & MIPS Review (9)

Conceptual tool box? Evaluation Techniques Levels of translation (e.g., Compilation) Levels of Interpretation (e.g., Microprogramming) Hierarchy (e.g, registers, cache, mem,disk,tape) Pipelining and Parallelism Indirection and Address Translation Synchronous /Asynchronous Control Transfer Timing, Clocking, and Latching CAD Programs, Hardware Description Languages, Simulation Static / Dynamic Scheduling Physical Building Blocks (e.g., Carry Lookahead) Understanding Technology Trends / FPGAs CS 152 L01 Introduction & MIPS Review (10)

Format: Lecture - Disc - Lecture - Lab Mon Labs due Tue Lecture Wed Homeworks due Thu Lecture Fri Discussion Section/Lab demo There IS discussion this week ; Prerequisite Quiz in 10 days (Friday in discussion section) CS 152 L01 Introduction & MIPS Review (11)

2 Discussion Sections 1. Noon - 2 PM 85 Evans (Brandon) 2. 2 PM - 4 PM 87 Evans (Doug) 2-hour discussion section for later in term. Early sections may end in 1 hour. Make sure that you are free for both hours however! Project team must be in same section! CS 152 L01 Introduction & MIPS Review (12)

To Do Now: Fill out Survey with Photo Survey is up now on the website in the "News" section at the top The deadline for turning in survey is Tuesday 9/7 Photo + survey of interesting items Survey of your views on cheating to help with departmental discussion CS 152 L01 Introduction & MIPS Review (13)

Typical 80-minute Lecture Format 18-Minute Lecture + 2-Min admin break 20-Minute Lecture + 10-Min Peer instruct. 25-Minute Lecture + 5-Min wrap-up We ll come to class early & try to stay after to answer questions Attention CS 152 L01 Introduction & MIPS Review (14) 20 min. Break Next Time thing In conclusion

Tried-and-True Technique: Peer Instruction Increase real-time learning in lecture, test understanding of concepts vs. details As complete a segment ask multiple choice question 1-2 minutes to decide yourself 3-4 minutes in pairs/triples to reach consensus. Teach each other! 2-3 minute discussion of answers, questions, clarifications CS 152 L01 Introduction & MIPS Review (15)

Homeworks and Labs/Projects Homework exercises (every 2 weeks) Lab Projects (every ~2 weeks) Lab 1 Write diagnostics to debug bad SPIM Lab 2 Single Cycle Processor Lab 3 Pipelined Processor Lab 4 Cache and Memory Interface All exercises, reading, homeworks, projects on course web page CS 152 L01 Introduction & MIPS Review (16)

Project/Lab Summary Tool Flow runs on PCs in 119 and 125 Cory, but 119 Cory is primary CS152 lab Get instructional UNIX/PC account now ( name account ); get in discussion End of semester Project finale: Demo Oral Presentation Head-to-head Race Final Report CS 152 L01 Introduction & MIPS Review (17)

Course Exams Reduce the pressure of taking exams Midterms: Tue October 12 th and Tue Nov. 23rd in 306 Soda 3 hrs to take 1.5-hr test (5:30-8:30 PM) Our goal: test knowledge vs. speed writing Review meetings: Sunday before? Both mid-terms can bring summary sheets Students/Staff meet over pizza after exam at LaVals! Allow us to meet you We ll buy! CS 152 L01 Introduction & MIPS Review (18)

Grading Grade breakdown Two Midterm Exams: 32% (combined) Labs: 30% Final Project 20% Homeworks: 8% Group/Class Participation: 10% No late homeworks or labs: our goal grade, return in 1 week Grades posted on home page/glookup? Written/email request for changes to grades EECS GPA guideline upper div. class: 2.7 to 3.1 average 152 grade = B/B+; set expectations accordingly CS 152 L01 Introduction & MIPS Review (19)

Our Goals Show you how to understand modern computer architecture in its rapidly changing form Show you how to design by leading you through the process on challenging design problems and by examining real designs Learn how to test and to design for test Reduce workload from prior semesters yet more computers working for head-tohead race Simpler homeworks 4 labs vs. 6 labs Simpler final project target CS 152 L01 Introduction & MIPS Review (20)

Course Problems Cheating What is cheating? Studying together in groups is encouraged Work must be your own (or your group s own) Common examples of cheating: work together on wording of answer to homework, running out of time on a assignment and then pick up output, take homework from box and copy, person asks to borrow solution just to take a look, copying an exam question, copy old projects, Homeworks/labs/projects/exams # points varies; 0 and possibly F in course Inform Chair and Office of Student Conduct CS 152 L01 Introduction & MIPS Review (21)

EECS Policy: www.eecs.berkeley.edu/policies/acad.dis.shtml Copying all or part of another person's work, or using reference material not specifically allowed, are forms of cheating and will not be tolerated. A student involved in an incident of cheating will be notified by the instructor and the following policy will apply: 1. The instructor may take actions such as: A. require repetition of the subject work, B. assign an F grade or a 'zero' grade to the subject work, C. for serious offenses, assign an F grade for the course. 2. The recommended action for cheating on examinations or term papers is 1(C). 3. The instructor must inform the student and the Department Chair in writing of the incident, the action taken, if any, and the student's right to appeal to the Chair of the Department Grievance Committee or to the Director of the Office of Student Conduct. 4. The instructor retains copies of any written evidence or observation notes. 5. The Department Chair must inform the Director of the Office of Student Conduct of the incident, the student's name, & action taken by the instructor. 6. The Office of Student Conduct may choose to conduct a formal hearing on the incident and to assess a penalty for misconduct. 7. The Department will recommend that students involved in a second incident of cheating be dismissed from the University. CS 152 L01 Introduction & MIPS Review (22)

Text Required: Computer Organization and Design: The Hardware/ Software Interface, 3rd Edition, Patterson and Hennessy (COD) 3rd edition $20 less than 2nd edition ($56 discounted vs. $100+ for competition) CD inside book includes manuals, appendices, simulators, CAD, Green card summarizes MIPS Readings on web page inst.eecs.berkeley.edu/~cs152 Need 3rd edition? Yes, since changed almost every page, CD, verilog, CS 152 L01 Introduction & MIPS Review (23)

MIPS I Instruction set CS 152 L01 Introduction & MIPS Review (24)

MIPS I Operation Overview Arithmetic Logical: Add, AddU, Sub, SubU, And, Or, Xor, Nor, SLT, SLTU AddI, AddIU, SLTI, SLTIU, AndI, OrI, XorI, LUI SLL, SRL, SRA, SLLV, SRLV, SRAV Memory Access: LB, LBU, LH, LHU, LW, LWL,LWR SB, SH, SW, SWL, SWR CS 152 L01 Introduction & MIPS Review (25)

MIPS logical instructions Instruction Example Meaning Comment and and $1,$2,$3 $1 = $2 & $3 3 reg. operands; Logical AND or or $1,$2,$3 $1 = $2 $3 3 reg. operands; Logical OR xor xor $1,$2,$3 $1 = $2 ^ $3 3 reg. operands; Logical XOR nor nor $1,$2,$3 $1 = ~($2 $3) 3 reg. operands; Logical NOR and immediate andi $1,$2,10 $1 = $2 & 10 Logical AND reg, constant or immediate ori $1,$2,10 $1 = $2 10 Logical OR reg, constant xor immediate xori $1, $2,10 $1 = $2 ^ 10 Logical XOR reg, constant shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant shift right arithm. sra $1,$2,10 $1 = $2 >> 10 Shift right (sign extend) shift left logical sllv $1,$2,$3 $1 = $2 << $3 Shift left by variable shift right logical shift right arithm. CS 152 L01 Introduction & MIPS Review (26) srlv $1,$2, $3 $1 = $2 >> $3 Shift right by variable srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by variable Q: Can some multiply by 2 i? Divide by 2 i? Invert?

M I P S Reference Data: CORE INSTRUCTION SET (1) NAME Add Add Immediate Branch On Equal MNE- MON- IC add addi beq FOR- MAT R I I OPERATION (in Verilog) R[rd] = R[rs] + R[rt] (1) R[rt] = R[rs] + SignExtImm (1)(2) if(r[rs]==r[rt]) PC=PC+4+ BranchAddr (4) OPCOD E/FUNC T (hex) 0 / 20 hex 8 hex 4 hex (1) May cause overflow exception (2) SignExtImm = { 16{immediate[15]}, immediate } (3) ZeroExtImm = { 16{1b 0}, immediate } (4) BranchAddr = { 14{immediate[15]}, immediate, 2 b0} CS 152 L01 Introduction & MIPS Review (27)

MIPS data transfer instructions Instruction Comment sw 500($4), $3 sh 502($2), $3 sb 41($3), $2 Store word Store half Store byte lw $1, 30($2) lh $1, 40($3) lhu $1, 40($3) lb $1, 40($3) lbu $1, 40($3) Load word Load halfword Load halfword unsigned Load byte Load byte unsigned lui $1, 40 Load Upper Immediate (16 bits shifted left by 16) Q: Why need lui? LUI R5 R5 0000 0000 CS 152 L01 Introduction & MIPS Review (28)

Multiply / Divide Start multiply, divide MULT rs, rt MULTU rs, rt DIV rs, rt DIVU rs, rt Registers Move result from multiply, divide MFHI rd MFLO rd HI LO Move to HI or LO MTHI rd MTLO rd CS 152 L01 Introduction & MIPS Review (29)

MIPS arithmetic instructions Instruction Example Meaning Comments add add $1,$2,$3 $1 = $2 + $3 3 operands; exception possible subtract sub $1,$2,$3 $1 = $2 $3 3 operands; exception possible add immediate addi $1,$2,100 $1 = $2 + 100 + constant; exception possible add unsigned addu $1,$2,$3 $1 = $2 + $3 3 operands; no exceptions subtract unsigned subu $1,$2,$3 $1 = $2 $3 3 operands; no exceptions add imm. unsign. addiu $1,$2,100 $1 = $2 + 100 + constant; no exceptions multiply mult $2,$3 Hi, Lo = $2 x $3 64-bit signed product multiply unsigned multu$2,$3 Hi, Lo = $2 x $3 64-bit unsigned product divide div $2,$3 Lo = $2 $3, Lo = quotient, Hi = remainder Hi = $2 mod $3 divide unsigned divu $2,$3 Lo = $2 $3, Unsigned quotient & remainder Hi = $2 mod $3 Move from Hi mfhi $1 $1 = Hi Used to get copy of Hi Move from Lo mflo $1 $1 = Lo Used to get copy of Lo Q: Which add for address arithmetic? Which add for integers? CS 152 L01 Introduction & MIPS Review (30)

When does MIPS sign extend? When value is sign extended, copy upper bit to full value: Examples of sign extending 8 bits to 16 bits: 00001010 00000000 00001010 10001100 11111111 10001100 When is an immediate operand sign extended? Arithmetic instructions (add, sub, etc.) always sign extend immediates even for the unsigned versions of the instructions! Logical instructions do not sign extend immediates (They are zero extended) Load/Store address computations always sign extend immediates Multiply/Divide have no immediate operands however: unsigned CS 152 L01 Introduction & MIPS Review (31) treat operands as unsigned The data loaded by the instructions lb and lh are extended as follows ( unsigned don t extend): lbu, lhu are zero extended lb, lh are sign extended Q: Then what is does add unsigned (addu) mean since not immediate?

Green Card: ARITHMETIC CORE INSTRUCTION SET (2) NAME Branch On FP True Load FP Single Divide MNE- MON- IC bc1t lwc1 div FOR- MAT FI I R OPERATION (in Verilog) if (FPcond) PC=PC + 4 + BranchAddr (4) F[rt] = M[R[rs] + SignExtImm] (2) Lo=R[rs]/R[rt]; Hi=R[rs]%R[rt] OPCODE /FMT / FT/ FUNCT (hex) 11/8/1/-- 11/8/1/-- 31/--/--/-- (1) May cause overflow exception (2) SignExtImm = { 16{immediate[15]}, immediate } (3) ZeroExtImm = { 16{1b 0}, immediate } (4) BranchAddr = { 14{immediate[15]}, immediate, 2 b0} CS 152 L01 Introduction & MIPS Review (32)

MIPS Compare and Branch Compare and Branch BEQ rs, rt, offset if R[rs] == R[rt] then PC-relative branch BNE rs, rt, offset <> Compare to zero and Branch BLEZ rs, offset BGTZ rs, offset > BLT < BGEZ >= if R[rs] <= 0 then PC-relative branch BLTZAL rs, offset if R[rs] < 0 then branch and link (into R 31) BGEZAL >=! Remaining set of compare and branch ops take two instructions Almost all comparisons are against zero! CS 152 L01 Introduction & MIPS Review (33)

MIPS jump, branch, compare instructions Instruction Example Meaning branch on equal beq $1,$2,100 if ($1 == $2) go to PC+4+100 Equal test; PC relative branch branch on not eq. bne $1,$2,100 if ($1!= $2) go to PC+4+100 Not equal test; PC relative set on less than slt $1,$2,$3 if ($2 < $3) $1=1; else $1=0 Compare less than; 2 s comp. set less than imm. slti $1,$2,100 if ($2 < 100) $1=1; else $1=0 Compare < constant; 2 s comp. set less than uns. sltu $1,$2,$3 if ($2 < $3) $1=1; else $1=0 Compare less than; natural numbers set l. t. imm. uns. sltiu $1,$2,100 if ($2 < 100) $1=1; else $1=0 Compare < constant; natural numbers jump j 10000 go to 10000 Jump to target address jump register jr $31 go to $31 For switch, procedure return jump and link jal 10000 $31 = PC + 4; go to 10000 For procedure call CS 152 L01 Introduction & MIPS Review (34)

Signed vs. Unsigned Comparison $1= 0 00 0000 0000 0000 0001 $2= 0 00 0000 0000 0000 0010 $3= 1 11 1111 1111 1111 1111 two two two After executing these instructions: slt $4,$2,$1 ; if ($2 < $1) $4=1; else $4=0 slt $5,$3,$1 ; if ($3 < $1) $5=1; else $5=0 sltu $6,$2,$1 ; if ($2 < $1) $6=1; else $6=0 sltu $7,$3,$1 ; if ($3 < $1) $7=1; else $7=0 What are values of registers $4 - $7? Why? $4 = ; $5 = ; $6 = ; $7 = ; CS 152 L01 Introduction & MIPS Review (35)

Signed vs. Unsigned Comparison $1= 0 00 0000 0000 0000 0001 $2= 0 00 0000 0000 0000 0010 $3= 1 11 1111 1111 1111 1111 two two two After executing these instructions: slt $4,$2,$1 ; if ($2 < $1) $4=1; else $4=0 slt $5,$3,$1 ; if ($3 < $1) $5=1; else $5=0 sltu $6,$2,$1 ; if ($2 < $1) $6=1; else $6=0 sltu $7,$3,$1 ; if ($3 < $1) $7=1; else $7=0 What are values of registers $4 - $7? Why? $4 = 0 ; $5 = 1 ; $6 = 0 ; $7 = 0 ; CS 152 L01 Introduction & MIPS Review (36)

MIPS assembler register convention Name Number Usage Preserved across a call? $zero 0 the value 0 n/a $v0-$v1 2-3 return values no $a0-$a3 4-7 arguments no $t0-$t7 8-15 temporaries no $s0-$s7 16-23 saved yes $t18-$t19 24-25 temporaries no $sp 29 stack pointer yes $ra 31 return address yes caller saved callee saved On Green Card in Column #2 at bottom CS 152 L01 Introduction & MIPS Review (37)

Peer Instruction: $s3=i, $s4=j, $s5=@a Loop:addiu $s4,$s4,1 # j = j + 1 sll $t1,$s3,2 # $t1 = 4 * i addu $t1,$t1,$s5 # $t1 = @ A[i] lw $t0,0($t1) # $t0 = A[i] slti $t1,$t0,10 # $t1 = $t0 < 10 beq $t1,$0, Loop # goto Loop [not delayed] addiu $s3,$s3,1 # i = i + 1 slti $t1,$t0, 0 # $t1 = $t0 < 0 bne $t1,$0, Loop # goto Loop [not delayed] do j = j + 1 while ( ); What C code properly fills in the blank in loop on right? 1: A[i++] >= 10 2: A[i++] >= 10 A[i] < 0 3: A[i] >= 10 A[i++] < 0 4: A[i++] >= 10 A[i] < 0 5: A[i] >= 10 && A[i++] < 0 6 None of the above CS 152 L01 Introduction & MIPS Review (38)

Peer Instruction: $s3=i, $s4=j, $s5=@a Loop:addiu $s4,$s4,1 # j = j + 1 sll $t1,$s3,2 # $t1 = 4 * i addu $t1,$t1,$s5 # $t1 = @ A[i] lw $t0,0($t1) # $t0 = A[i] slti $t1,$t0,10 # $t1 = $t0 < 10 beq $t1,$0, Loop # goto Loop if $t1 == 0 ($t0 >= 10) addiu $s3,$s3,1 # i = i + 1 slti $t1,$t0, 0 # $t1 = $t0 < 0 bne $t1,$0, Loop # goto Loop if $t1!= 0 ($t0 < 0) What C code properly fills in the blank in loop on right? 1: A[i++] >= 10 2: A[i++] >= 10 A[i] < 0 3: A[i] >= 10 A[i++] < 0 4: A[i++] >= 10 A[i] < 0 5: A[i] >= 10 && A[i++] < 0 6: None of the above do j = j + 1 while ( ); CS 152 L01 Introduction & MIPS Review (39)

Instruction Formats I-format: used for instructions with immediates, lw and sw (since the offset counts as an immediate), and the branches (beq and bne), (but not the shift instructions; later) J-format: used for j and jal R-format: used for all other instructions It will soon become clear why the instructions have been partitioned in this way. CS 152 L01 Introduction & MIPS Review (40)

R-Format Instructions (1/2) Define fields of the following number of bits each: 6 + 5 + 5 + 5 + 5 + 6 = 32 6 5 5 5 5 6 For simplicity, each field has a name: opcode rs rt rd shamt funct CS 152 L01 Introduction & MIPS Review (41)

R-Format Instructions (2/2) More fields: rs (Source Register): generally used to specify register containing first operand rt (Target Register): generally used to specify register containing second operand (note that name is misleading) rd (Destination Register): generally used to specify register which will receive result of computation CS 152 L01 Introduction & MIPS Review (42)

J-Format Instructions (1/2) Define fields of the following number of bits each: 6 bits 26 bits As usual, each field has a name: opcode target address Key Concepts Keep opcode field identical to R-format and I-format for consistency. Combine all other fields to make room for large target address. CS 152 L01 Introduction & MIPS Review (43)

J-Format Instructions (2/2) Summary: New PC = { PC[31..28], target address, 00 } Understand where each part came from! Note: In Verilog, {,, } means concatenation { 4 bits, 26 bits, 2 bits } = 32 bit address { 1010, 11111111111111111111111111, 00 } = 10101111111111111111111111111100 We use Verilog in this class CS 152 L01 Introduction & MIPS Review (44)

R-Format Example MIPS Instruction: add $8,$9,$10 Decimal number per field representation: 0 9 10 8 0 32 Binary number per field representation: 000000 01001 01010 01000 00000 100000 hex representation: 012A 4020 hex hex decimal representation: 19,546,144 ten On Green Card: Format in column 1, opcodes in column 3 CS 152 L01 Introduction & MIPS Review (45)

MIPS opcode (31:26) (1) j lui lbu Green Card: OPCODES, BASE CONVERSION, ASCII (3) (1) MIPS funct (5:0) sll srl sync and (2) MIPS funct (5:0) add.f mul.f floor.w.f cvt.w.f Binary 00 0000 00 0010 00 1111 10 0100 Hexadecimal Decimal 0 2 15 36 0 2 f 24 ASCII NUL STX (1) opcode(31:26) == 0 (2) opcode(31:26) == 17 ten (11 hex ); if fmt(25:21)==16 ten (10 hex ) f = s (single); if fmt(25:21)==17 ten (11 hex ) f = d (double) Note: 3-in-1 - Opcodes, base conversion, ASCII! SI $ CS 152 L01 Introduction & MIPS Review (46)

Green Card green card /n./ [after the "IBM System/360 Reference Data" card] A summary of an assembly language, even if the color is not green. For example, Image from Dave's Green Card Collection: http://www.planetmvs.com/greencard/ "I'll go get my green card so I can check the addressing mode for that instruction." www.jargon.net CS 152 L01 Introduction & MIPS Review (47)

Peer Instruction Which instruction has same representation as 35 ten? A. add $0, $0, $0 B. subu $s0,$s0,$s0 C. lw $0, 0($0) D. addi $0, $0, 35 E. subu $0, $0, $0 F. Trick question! Instructions are not numbers Use Green Card handout to answer CS 152 L01 Introduction & MIPS Review (48)

Peer Instruction Which instruction has same representation as 35 ten? A. add $0, $0, $0 opcode rs rt rd shamt funct B. subu $s0,$s0,$s0 opcode rs rt rd shamt funct C. lw $0, 0($0) opcode rs rt offset D. addi $0, $0, 35 E. subu $0, $0, $0 F. Trick question! opcode rs opcode rs rt rt immediate rd shamt funct Instructions are not numbers Registers numbers and names: 0: $0, 8: $t0, 9:$t1,..15: $t7, 16: $s0, 17: $s1,.. 23: $s7 Opcodes and function fields (if necessary) add: opcode = 0, funct = 32 subu: opcode = 0, funct = 35 addi: opcode = 8 lw: opcode = 35 CS 152 L01 Introduction & MIPS Review (49)

Peer Instruction Which instruction bit pattern = number 35? A. add $0, $0, $0 B. subu $s0,$s0,$s0 C. lw $0, 0($0) D. addi $0, $0, 35 E. subu $0, $0, $0 F. Trick question! Instructions!= numbers 0 0 0 0 16 16 35 0 0 0 Registers numbers and names: 0: $0, 8: $t0, 9:$t1,,16: $s0, 17: $s1,, Opcodes and function fields add: opcode = 0, function field = 32 subu: opcode = 0, function field = 35 addi: opcode = 8 CS 152 lw: L01 Introduction opcode & MIPS Review = (50) 35 0 0 32 16 0 35 8 0 0 35 0 0 0 0 0 35

Branch & Pipelines Time li $3, #7 sub $4, $4, 1 execute ifetch execute bz $4, LL ifetch execute Branch addi $5, $3, 1 ifetch execute Delay Slot LL: slt $1, $3, $5 Branch Target ifetch execute By the end of Branch instruction, the CPU knows whether or not the branch will take place. However, it will have fetched the next instruction by then, regardless of whether or not a branch will be taken. Why not execute it? CS 152 L01 Introduction & MIPS Review (51)

Delayed Branches li $3, #7 sub $4, $4, 1 bz $4, LL addi $5, $3, 1 subi $6, $6, 2 LL: slt $1, $3, $5 In the Raw MIPS, the instruction after the branch is executed even when the branch is taken This is hidden by the assembler for the MIPS virtual machine allows the compiler to better utilize the instruction pipeline (???) Jump and link (jal inst): Put the return addr. Into link register ($31): - PC+4 (logical architecture) - PC+8 physical ( Raw ) architecture Then jump to destination address Delay Slot Instruction delay slot executed CS 152 L01 Introduction & MIPS Review (52)

Filling Delayed Branches Branch: Inst Fetch execute successor even if branch taken! Then branch target or continue Dcd & Op Fetch Execute Inst Fetch Dcd & Op Fetch Inst Fetch Execute Single delay slot impacts the critical path Compiler can fill a single delay slot with a useful instruction 50% of the time. try to move down from above jump move up from target, if safe add $3, $1, $2 sub $4, $4, 1 bz $4, LL NOP... LL: add rd,... Is this violating the ISA abstraction? CS 152 L01 Introduction & MIPS Review (53)

Summary: Salient features of MIPS I 32-bit fixed format inst (3 formats) 32 32-bit GPR (R0 contains zero) and 32 FP registers (and HI LO) partitioned by software convention 3-address, reg-reg arithmetic instr. Single address mode for load/store: base+displacement no indirection, scaled 16-bit immediate plus LUI Simple branch conditions compare against zero or two registers for =, no integer condition codes Delayed branch execute instruction after a branch (or jump) even if the branch is taken (Compiler can fill a delayed branch with useful work about 50% of the time) CS 152 L01 Introduction & MIPS Review (54)

TAs Douglas Densmore Ted Hong Brandon Ooi CS 152 L01 Introduction & MIPS Review (55)

And in conclusion... Continued rapid improvement in Computing 2X every 1.5 years in processor speed; every 2.0 years in memory size; every 1.0 year in disk capacity; Moore s Law enables processor, memory (2X transistors/chip/ ~1.5 ro 2.0 yrs) 5 classic components of all computers Control Datapath Memory Input Output Processor CS 152 L01 Introduction & MIPS Review (56)