Instructors: Randy H. Katz David A. PaHerson hhp://inst.eecs.berkeley.edu/~cs61c/fa10. Fall Lecture #6. Agenda

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

Agenda. Review 2/10/11. CS 61C: Great Ideas in Computer Architecture (Machine Structures)

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

Reduced Instruction Set Computer (RISC)

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

CS 61c: Great Ideas in Computer Architecture

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

CS61C : Machine Structures

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

Reduced Instruction Set Computer (RISC)

Thomas Polzer Institut für Technische Informatik

COMP MIPS instructions 2 Feb. 8, f = g + h i;

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

UCB CS61C : Machine Structures

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

ECE260: Fundamentals of Computer Engineering

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

ECE260: Fundamentals of Computer Engineering

Instructions: Language of the Computer

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

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

Lecture 4: MIPS Instruction Set

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

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

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

CS 61C: Great Ideas in Computer Architecture. MIPS Instruc,on Representa,on II. Dan Garcia

Levels of Programming. Registers

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

Lecture 5: Procedure Calls

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

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

Computer Architecture. The Language of the Machine

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

MIPS Instruction Set

Unsigned Binary Integers

Instructors: Randy H. Katz David A. PaKerson hkp://inst.eecs.berkeley.edu/~cs61c/fa10. Fall Lecture #11. Agenda

Unsigned Binary Integers

CS3350B Computer Architecture MIPS Instruction Representation

Chapter 2A Instructions: Language of the Computer

Computer Architecture. MIPS Instruction Set Architecture

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

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

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

The MIPS Instruction Set Architecture

CS 61c: Great Ideas in Computer Architecture

Instructions: Language of the Computer

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

MIPS%Assembly% E155%

CS61C : Machine Structures

Topic Notes: MIPS Instruction Set Architecture

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

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

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

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner. Topic 3: Arithmetic

CS3350B Computer Architecture MIPS Introduction

CS61C : Machine Structures

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

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

Lecture 9: Disassembly

Computer Architecture. Chapter 3: Arithmetic for Computers

We will study the MIPS assembly language as an exemplar of the concept.

Chapter Two MIPS Arithmetic

CS61C : Machine Structures

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

CS3350B Computer Architecture

CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14

CS222: MIPS Instruction Set

CS 61C: Great Ideas in Computer Architecture Compilers and Floa-ng Point. Today s. Lecture

Review of Last Lecture. CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Representation II. Agenda. Dealing With Large Immediates

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Chapter 2. Instructions: Language of the Computer

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS61C : Machine Structures

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

Computer Architecture

CS 4200/5200 Computer Architecture I

Computer Architecture

Arithmetic for Computers

Review: MIPS Organization

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

CENG3420 Lecture 03 Review

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

Course Administration

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

CS 61C: Great Ideas in Computer Architecture Func%ons and Numbers

Systems Architecture I

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

COMPUTER ORGANIZATION AND DESIGN

Chapter 2: Instructions:

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

Transcription:

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Instructors: Randy H. Katz David A. PaHerson hhp://inst.eecs.berkeley.edu/~cs61c/fa10 Fall 2010 - - Lecture #6 1 Agenda Review Overflow and Real Numbers Administrivia Technology Break InstrucZons as Numbers Assembly Language to Machine Language Summary Fall 2010 - - Lecture #6 2 1

Review from Last Lecture Registers seleczvely saved/restored on call Saved registers $s0- $s7; temporary regs $t0- $t9 not saved C splits memory into text, stazc, heap, stack, with registers dedicated to support: $gp, $sp, $fp Program can interpret binary number as unsigned integer, two s complement signed integer, floazng point number, ASCII characters, Unicode characters, Integers have largest posizve and largest negazve numbers, but represent all in between Two s comp. wierdness is one extra negazve num Fall 2010 - - Lecture #5 3 What if result of operazon doesn t fit in 32 bits? Called overflow: calculate too big a number to represent within a word Unsigned numbers: 1 + 4,294,967,295 (2 32-1) Signed numbers: 1 + 2,147,483,647 (2 31-1) Fall 2010 - - Lecture #5 4 2

Answer Depends on Language C unsigned number arithmezc ignores overflow (arithmezc modulo 2 32 ) 1 + 4,294,967,295 = C signed number arithmezc also ignores overflow 1 + 2,147,483,647 (2 31-1) = Other languages want overflow signal on signed numbers (e.g., Fortran) What s a computer architect to do? Fall 2010 - - Lecture #5 5 MIPS SoluZon: offer both InstrucZons that overflow: add, sub, mult, div, addi, mulz, divi InstrucZons that don t overflow called unsigned (but really means no overflow): addu, subu, multu, divu, addiu, mulzu, diviu Given semanzcs of C, always use unsigned versions Note: slt and slz do signed comparisons, while sltu and slzu do unsigned comparisons Nothing to do with overflow When would get different answer for slt vs. sltu? Fall 2010 - - Lecture #5 6 3

What about Real Numbers? Normalized scienzfic notazon (aka standard form or exponenzal notazon): r x E i, E is where exponent (usually 10), i is a posizve or negazve integer, r is a real number 1.0, < 10 61 is 6.10 x 10 2, 0.000061 is 6.10 x10-5 Computers version of normalized scienzfic notazon called Floa,ng Point notazon r x E i, E where is exponent (2), i is a posizve or negazve integer, r is a real number 1.0, < 2 Fall 2010 - - Lecture #5 7 FloaZng Point Numbers 32- bit word has 2 32 paherns, so must be approximazon of real numbers 1.0, < 2 IEEE 754 FloaZng Point Standard: 1 bit for sign (s) of floazng point number 8 bits for exponent (E) 23 bits for frac,on (F) (get 1 extra bit of precision if leading 1 is implicit) (- 1) s x (1 + F) x 2 E Can represent from 2.0 x 10-38 to 2.0 x 10 38 Fall 2010 - - Lecture #5 8 4

FloaZng Point Numbers What about bigger or smaller numbers? IEEE 754 FloaZng Point Standard: Double Precision (64 bits) 1 bit for sign (s) of floazng point number 11 bits for exponent (E) 52 bits for frac,on (F) (get 1 extra bit of precision if leading 1 is implicit) (- 1) s x (1 + F) x 2 E Can represent from 2.0 x 10-308 to 2.0 x 10 308 32 bit format called Single Precision Fall 2010 - - Lecture #5 9 More FloaZng Point What about 0? Bit pahern all 0s means 0, so no implicit leading 1 What if divide 1 by 0? Can get infinity symbols +, - Sign bit 0 or 1, largest exponent, 0 in fraczon What if do something stupid? (, 0 0) Can get special symbols NaN for Not- a- Number Sign bit 0 or 1, largest exponent, not zero in fraczon What if result is too big? (2x10 308 x 2x10 2 ) Get overflow in exponent, alert programmer! What if result is too small? (2x10-308 2x10 2 ) Get underflow in exponent, alert programmer! Fall 2010 - - Lecture #5 10 5

MIPS FloaZng Point InstrucZons C, Java has single precision (float) and double precision (double) types MIPS instruczons:.s for single,.d for double Fl. Pt. AddiZon single precision: Fl. Pt. AddiZon double precision: Fl. Pt. SubtracZon single precision: Fl. Pt. SubtracZon double precision: Fl. Pt. MulZplicaZon single precision: Fl. Pt. MulZplicaZon double precision: Fl. Pt. Divide single precision: Fl. Pt. Divide double precision: Fall 2010 - - Lecture #5 11 MIPS FloaZng Point InstrucZons C, Java has single precision (float) and double precision (double) types MIPS instruczons:.s for single,.d for double Fl. Pt. Comparison single precision: Fl. Pt. Comparison double precision: Fl. Pt. branch: Since rarely mix integers and Fl. Pt., MIPS has separate registers for floazng- point operazons: $f0, $f1,, $f31 Double precision uses adjacent even- odd pairs of registers: $f0 and $f1, $f2 and $f3, $f4 and $f5,, $f30 and $f31 Need data transfer instruczons for these new registers lwc1 (load word), swc1 (store word) Double precision uses two lwc1 instruczons, two swc1 instruczons Fall 2010 - - Lecture #5 12 6

Peer InstrucZon Suppose Big, Tiny, and BigNegaZve are doubles in C, with Big inizalized to a big number (seconds/century or π x 10 9 ), Tiny to a small number (seconds/picosecond or 1.0 x 10-12 ), BigNegaZve = - Big. Two condizonals about associazvity: I. (Big * Tiny) * BigNegaZve == (Big * BigNegaZve) * Tiny II. (Big + Tiny) + BigNegaZve == (Big + BigNegaZve) + Tiny Which statement below is correct? A. I. is false and II. is false B. I. is false and II. is true C. I. is true and II. is false D. I. is true and II. is true Fall 2010 - - Lecture #6 13 Piyall FloaZng point addizon is NOT associazve Some opzmizazons can change order of floazng point computazons, which can change results Need to ensure that floazng point algorithm is correct even with opzmizazons Fall 2010 - - Lecture #5 14 7

Peer InstrucZon Increase real- Zme learning in lecture, test understanding of concepts vs. details mazur-www.harvard.edu/education/pi.phtml As complete a segment ask mulzple choice queszon 1-2 minutes: decide yourself, vote 2-3 minutes: discuss in pairs, then team vote; flash cards Try to convince partner; learn by teaching Fall 2010 - - Lecture #6 15 InstrucZons as Numbers InstrucZons are kept as binary numbers in memory too Stored program concept As easy to change programs as it is to change data Saw mapping of register names to numbers Need to map instruczon operazon to a part of number Fall 2010 - - Lecture #6 16 8

InstrucZons as Numbers addu $t0,$s1,$s2 DesZnaZon register $t0 is register 8 Source register $s1 is register 17 Source register $s2 is register 18 Add unsigned instruczon encoded as number 33 0 17 18 8 0 33 000000 10001 10010 01000 00000 100001 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits Groups of bits call fields (unused field default is 0) Layout called instruc,on format Binary version called machine instruc,on Fall 2010 - - Lecture #6 17 InstrucZons as Numbers sll $zero,$zero,0 $zero is register 0 Shi{ amount 0 is 0 Shi{ le{ logical instruczon encoded as number 0 0 0 0 0 0 0 000000 00000 00000 00000 00000 000000 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits Can also represent machine code as base 16 or base 8 number: 0000 0000 hex, 0000000000 oct Fall 2010 - - Lecture #6 18 9

Everything in a computer is just a Binary Number Up to program to decide what data means Example 32- bit data shown as binary number: 0000 0000 0000 0000 0000 0000 0000 0000 two What does it mean if its treated as 1. Signed integer 2. Unsigned integer 3. FloaZng point 4. ASCII characters 5. Unicode characters 6. MIPS instruczon Fall 2010 - - Lecture #6 19 ImplicaZons of everything is a number? Stored program concept Invented about 1947 (many claim invenzon) As easy to change programs as to change data! ImplicaZons? Fall 2010 - - Lecture #6 20 10

Names of MIPS fields op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits op: Basic operazon of instruczon, or opcode rs: 1 st register source operand rt: 2 nd register source operand. rd: register desznazon operand (result of operazon) shamt: Shi{ amount. funct: FuncZon. This field, o{en called func,on code, selects the specific variant of the operazon in the op field Fall 2010 - - Lecture #6 21 What about load, store, immediate, branches, jumps? Fields for constants only 5 bits (- 16 to +15) Too small for many common cases #1 Simplicity favors regularity (all instruczons use one format) vs. #3 Make common case fast (mulzple instruczon formats)? 4 th Design Principle: Good design demands good compromises BeHer to have mulzple instruczon formats and keep all MIPS instruczons same size All MIPS instruczons are 32 bits or 4 bytes Fall 2010 - - Lecture #6 22 11

Names of MIPS fields in I- type op rs rt address or constant 6 bits 5 bits 5 bits 16 bits op: Basic operazon of instruczon, or opcode rs: 1 st register source operand rt: 2 nd register source operand for branches but register desznazon operand for lw, sw, and immediate operazons Address/constant: 16- bit two s complement number Note: equal in size of rd, shamt, funct fields Fall 2010 - - Lecture #6 23 Register (R), Immediate (I), Jump (J) InstrucZon Formats R- type I- type op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits Now loads, stores, branches, and immediates can have 16- bit two s complement address or constant: - 32,768 (- 2 15 ) to +32,767 (2 15-1) What about jump, jump and link? J- type op rs rt address or constant 6 bits 5 bits 5 bits 16 bits op address 6 bits 26 bits Fall 2010 - - Lecture #6 24 12

InstrucZon Encoding of MIPS InstrucZons: Must Be Unique! For mat op rs rt rd shamt funct address addu R 0 reg reg reg 0 33 ten n.a. subu R 0 reg reg reg 0 35 ten n.a. sltu R 0 reg reg reg 0 43 ten n.a. sll R 0 reg n.a reg constant 0 ten n.a. addi unsigned I 9 ten reg reg n.a. n.a. n.a. constant lw (load word) I 35 ten reg reg n.a. n.a. n.a. address sw (store word) I 43 ten reg reg n.a. n.a. n.a. address beq I 4 ten reg reg n.a. n.a. n.a. address bne I 5 ten reg reg n.a. n.a. n.a. address j (jump) J 2 ten n.a. n.a. n.a. n.a. n.a. address jal J 3 ten n.a. n.a. n.a. n.a. n.a. address jr (jump reg) R 0 reg reg reg 0 8 ten n.a. Fall 2010 - - Lecture #6 25 ConverZng C to MIPS Machine code &A=$t0 (reg 8), $t1 (reg 9), h=$s2 (reg 18) A[300] = h + A[300]; Format? lw $t0,1200($t1) addu $t1,$s2,$t0 sw $t0,1200($t1) InstrucZon For mat op rs rt rd shamt funct address addu R 0 reg reg reg 0 33 ten n.a. lw (load word) I 35 ten reg reg n.a. n.a. n.a. address sw (store word) I 43 ten reg reg n.a. n.a. n.a. address R- type op rs rt rd shamt funct I- type op rs rt address or constant J- type op address Fall 2010 - - Lecture #6 26 13

I- type Addressing in Branches op rs rt address or constant 6 bits 5 bits 5 bits 16 bits Programs much bigger than 2 16 bytes, but branch address must fit in 16- bit field Must specify a register for branch addresses for big programs: PC = Register + Branch address Which register? CondiZonal branching for IF- statement, loops Tend to be near branches; ½ within 16 instruczons Idea: PC- rela,ve branching Fall 2010 - - Lecture #6 27 I- type Addressing in Branches op rs rt Hardware increments PC early, so relazve address is PC = (PC + 4) + Branch address Another opzmizazon since all MIPS instruczons 4 bytes long? MulZply value in branch address field by 4! MIPS PC- relazve branching PC = (PC + 4) + (Branch address*4) address or constant 6 bits 5 bits 5 bits 16 bits Fall 2010 - - Lecture #6 28 14

J- type op Addressing in Jumps address 6 bits 26 bits Same trick for Jumps, Jump and Link PC = Jump address * 4 Since PC = 32 bits, and Jump address * 4 = 28 bits, what about other 4 bits? Jump and Jump and Link only changes bohom 28 bits of PC Fall 2010 - - Lecture #6 29 Add ress 800 804 808 812 816 ConverZng to MIPS Machine code Loop: sll $t1,$s3,2 addu $t1,$t1,$s6 lw $t0,0($t1) bne $t0,$s5, Exit addiu $s3,$s3,1 820 j Loop Exit: R- type I- type J- type Format? op rs rt rd shamt funct op rs rt address or constant op address Fall 2010 - - Lecture #6 30 15

32 bit constants in MIPS Can create a 32- bit constant from two 32- bit MIPS instruczons Load Upper Immediate (lui or Louie ) puts 16 bits into upper 16 bits of desznazon register MIPS to load 32- bit constant into register $s0? 0000 0000 0011 1101 0000 1001 0000 0000 two lui $s0, 61 # 61 = 0000 0000 0011 1101 two ori $s0, $s0, 2304 # 2304 = 0000 1001 0000 0000 two Fall 2010 - - Lecture #6 32 Assembly and Pseudo- instruczons Turning textual MIPS instruczons into machine code called assembly, program called assembler Calculates addresses, maps register names to numbers, produces binary machine language Textual language called assembly language Can also accept instruczons convenient for programmer but not in hardware Load immediate (li) allows 32- bit constants, assembler turns into lui + ori (if needed) Load double (ld) uses two lwc1 instruczons to load a pair of 32- bit floazng point registers Called Pseudo- Instruc,ons Fall 2010 - - Lecture #6 33 16

Summary Integer and floazng point operazons can lead to results too big to store within their representazons: overflow/ underflow FloaZng point is an approximazon of reals Everything is a (binary) number in a computer InstrucZons and data; stored program concept MIPS ISA guided by 4 design principles: 1. Simplicity favors regularity 2. Smaller is faster 3. Make the common case fast 4. Good design demands good compromises Assemblers can enhance machine instruczon set for convenience of assembly- language programmer Fall 2010 - - Lecture #6 34 17