Computer Organization and Design Jair Gonzalez Enero 2004 MIPS ISA.

Slides:



Advertisements
Similar presentations
Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Advertisements

CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Assembly Language (cont)
CS 61C L13Introduction to MIPS: Instruction Representation I (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Chapter 2 Instructions: Language of the Computer Part III.
Computer Architecture ECE 361 Lecture 6: ALU Design
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
1  1998 Morgan Kaufmann Publishers and UCB CEG3420 Computer Design Lecture 4 MIPS Instruction Set Philip Leong.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 08 MIPS Instruction Representation I Lecturer SOE Dan Garcia
CS61C L10 : MIPS Instruction Representation II (1) Pearce, Summer 2010 © UCB inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 MIPS.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 13 MIPS Instruction Representation I Shanghai Jiaotong University and Lanxiang.
CS 61C L09 Instruction Format (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #9: MIPS Instruction.
EECC550 - Shaaban #1 Lec # 2 Winter Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions.
Reduced Instruction Set Computer (RISC)
CS61C L13 MIPS Instruction Representation I (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
CS61C L13 Introduction to MIPS: Instruction Representation I (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
CS61C L9 MIPS Logical & Shift Ops, and Instruction Representation I (1) Beamer, Summer 2007 © UCB Scott Beamer, Instructor inst.eecs.berkeley.edu/~cs61c.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Instruction Representation I (1) Fall 2005 Lecture 05: INSTRUCTION REPRESENTATION.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 13 MIPS Instruction Representation I The National Science Foundation (NSF)
EECC550 - Shaaban #1 Lec # 2 Winter Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions.
331 Practice Exam.1Fall 2003 Naming Conventions for Registers 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function.
EECC550 - Shaaban #1 Lec # 2 Winter (Chapter 2) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
CPE 442 Lec4.1 Intro Computer Architectures CpE 442 Computer Architecture and Engineering MIPS Instruction Set Architecture.
EECC250 - Shaaban #1 lec #21 Winter Complex Instruction Set Computer (CISC) Emphasizes doing more with each instruction. Motivated by the high.
1 IKI20210 Pengantar Organisasi Komputer Kuliah Minggu ke-4b: Bahasa Rakitan MIPS I diadaptasikan dari materi kuliah CS61C/2000 & CS152/1997  2000/1997.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Fall EE 333 Lillevik 333f06-l5 University of Portland School of Engineering Computer Organization Lecture 5 MIPS Instructions Loops Machine Instructions.
CS 152 L01 Introduction & MIPS Review (1)Patterson Fall 2003 © UCB Dave Patterson ( www-inst.eecs.berkeley.edu/~cs152/
Intro & ISA.1 1/14 Instruction Set Architecture (ISA) (Ch: , th ed) Instructions: Language of the Computer Dr. Khaled El-Ayat.
CENG 311 Instruction Representation
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
MIPS Instructions Instructions: Language of the Machine
MIPS Assembly Language Chapter 13 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
MIPS Assembly Language Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
Digital System Design II 数字系统设计 II Peng Liu ( 刘鹏 ) Dept. of Info. Sci. & Elec. Engg. Zhejiang University
CDA 3101 Spring 2016 Introduction to Computer Organization
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
Pirouz Bazargan SabetDecember 2003 Effective Implementation of a 32-bit RISC Processor Pirouz Bazargan Sabet University of Paris 6 - LIP6 - ASIM
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
Instruction Representation. Levels of Representation (abstractions) High Level Language Program (e.g., C) Assembly Language Program (e.g.,MIPS) Machine.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 08 MIPS Instruction Representation I Guest Lecturer Alan Christopher
Instructor: Prof. Hany H Ammar, LCSEE, WVU
IT 251 Computer Organization and Architecture
Computer Organization and Design Instruction Sets - 2
Computer Organization and Design Instruction Sets - 2
IT 251 Computer Organization and Architecture
32-bit MIPS ISA.
Computer Organization & Design
Computer Organization and Design Instruction Sets
Digital System Design II 数字系统设计II
Appendix A Classifying Instruction Set Architecture
MPIS Instructions Functionalities of instructions Instruction format
“so many gadgets, so many aches” - NYT
Computer Architecture & Operations I
ECE232: Hardware Organization and Design
Today’s Lecture Quick Review of Last Lecture
Flow of Control -- Conditional branch instructions
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Flow of Control -- Conditional branch instructions
CS352H Computer Systems Architecture
Reduced Instruction Set Computer (RISC)
MIPS Arithmetic and Logic Instructions
MIPS Arithmetic and Logic Instructions
Presentation transcript:

Computer Organization and Design Jair Gonzalez Enero 2004 MIPS ISA

Enero 2004 Where is “Computer Architecture and Engineering”? I/O systemProcessor Compiler Operating System (Windows 2K) Application (Netscape) Digital Design Circuit Design ISA Datapath & Control transistors Memory Hardware Software Assembler

Enero components of any Computer Processor Computer Control (“brain”) Datapath (“muscle”) Memory (where programs, data live when running) Devices Input Output Keyboard, Mouse Display, Printer Disk (where programs, data live when not running)

Enero 2004 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.

Enero 2004 TransistorsTechnology Trends 2X transistors/Chip Every 1.5 years Called “Moore’s Law” Alpha 21264: 15 million Pentium Pro: 5.5 million PowerPC 620: 6.9 million Alpha 21164: 9.3 million Sparc Ultra: 5.2 million Moore’s Law Athlon (K7): 22 Million

Enero 2004 " 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 MIPS I Operation Overview

Enero 2004 " Start multiply, divide – MULT rs, rt – MULTU rs, rt – DIV rs, rt – DIVU rs, rt " Move result from multiply, divide – MFHI rd – MFLO rd " Move to HI or LO – MTHI rd – MTLO rd Registers HILO Multiply / Divide Why not a third field for destination?

Enero 2004 Bit: 0, 1 Bit String: sequence of bits of a particular length 4 bits is a nibble 8 bits is a byte 16 bits is a half-word 32 bits is a word 64 bits is a double-word Character: ASCII 7 bit code UNICODE 16 bit code Decimal: digits 0-9 encoded as 0000b thru 1001b two decimal digits packed per 8 bit byte Integers: 2's Complement Floating Point(IEEE Standard): Single Precision Double Precision Extended Precision Data Types M x R E How many +/- #'s? Where is decimal pt? How are +/- exponents represented? exponent base mantissa

Enero 2004 InstructionExampleMeaningComments add add $1,$2,$3$1 = $2 + $33 operands; exception possible subtractsub $1,$2,$3$1 = $2 – $33 operands; exception possible add immediateaddi $1,$2,100$1 = $ constant; exception possible add unsignedaddu $1,$2,$3$1 = $2 + $33 operands; no exceptions subtract unsignedsubu $1,$2,$3$1 = $2 – $33 operands; no exceptions add imm. unsign.addiu $1,$2,100$1 = $ constant; no exceptions multiply mult $2,$3Hi, Lo = $2 x $364-bit signed product multiply unsignedmultu$2,$3Hi, Lo = $2 x $364-bit unsigned product divide div $2,$3Lo = $2 ÷ $3,Lo = quotient, Hi = remainder Hi = $2 mod $3 divide unsigned divu $2,$3Lo = $2 ÷ $3,Unsigned quotient & remainder Hi = $2 mod $3 Move from Himfhi $1$1 = HiUsed to get copy of Hi Move from Lomflo $1$1 = LoUsed to get copy of Lo MIPS arithmetic instructions Q: Which add for address arithmetic? Which add for integers?

Enero 2004 MIPS logical instructions InstructionExampleMeaningComment and and $1,$2,$3$1 = $2 & $33 reg. operands; Logical AND oror $1,$2,$3$1 = $2 | $33 reg. operands; Logical OR xorxor $1,$2,$3$1 = $2 ^  $33 reg. operands; Logical XOR nornor $1,$2,$3$1 = ~($2 |$3)3 reg. operands; Logical NOR and immediateandi $1,$2,10$1 = $2 & 10Logical AND reg, constant or immediateori $1,$2,10$1 = $2 | 10Logical OR reg, constant xor immediate xori $1, $2,10 $1 = ~$2 &~10Logical XOR reg, constant shift left logicalsll $1,$2,10$1 = $2 << 10Shift left by constant shift right logicalsrl $1,$2,10$1 = $2 >> 10Shift right by constant shift right arithm.sra $1,$2,10$1 = $2 >> 10Shift right (sign extend) shift left logicalsllv $1,$2,$3$1 = $2 << $3 Shift left by variable shift right logicalsrlv $1,$2, $3 $1 = $2 >> $3 Shift right by variable shift right arithm.srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by variable Q: Can some multiply by 2 i ? Divide by 2 i ? Invert?

Enero 2004 MIPS logical instructions InstructionExampleMeaningComment and and $1,$2,$3$1 = $2 & $33 reg. operands; Logical AND oror $1,$2,$3$1 = $2 | $33 reg. operands; Logical OR xorxor $1,$2,$3$1 = $2 ^  $33 reg. operands; Logical XOR nornor $1,$2,$3$1 = ~($2 |$3)3 reg. operands; Logical NOR and immediateandi $1,$2,10$1 = $2 & 10Logical AND reg, constant or immediateori $1,$2,10$1 = $2 | 10Logical OR reg, constant xor immediate xori $1, $2,10 $1 = ~$2 &~10Logical XOR reg, constant shift left logicalsll $1,$2,10$1 = $2 << 10Shift left by constant shift right logicalsrl $1,$2,10$1 = $2 >> 10Shift right by constant shift right arithm.sra $1,$2,10$1 = $2 >> 10Shift right (sign extend) shift left logicalsllv $1,$2,$3$1 = $2 << $3 Shift left by variable shift right logicalsrlv $1,$2, $3 $1 = $2 >> $3 Shift right by variable shift right arithm.srav $1,$2, $3 $1 = $2 >> $3 Shift right arith. by variable Q: Can some multiply by 2 i ? Divide by 2 i ? Invert?

Enero 2004 MIPS data transfer instructions InstructionComment sw 500($4), $3Store word sh 502($2), $3Store half sb 41($3), $2Store byte lw $1, 30($2)Load word lh $1, 40($3)Load halfword lhu $1, 40($3)Load halfword unsigned lb $1, 40($3)Load byte lbu $1, 40($3)Load byte unsigned lui $1, 40Load Upper Immediate (16 bits shifted left by 16)

Enero 2004 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:   " 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”  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

Enero 2004 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 if R[rs] <= 0 then PC-relative branch – BGTZ rs, offset > – BLT < – BGEZ >= – 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!

Enero 2004 MIPS jump, branch, compare instructions InstructionExampleMeaning branch on equalbeq $1,$2,100if ($1 == $2) go to PC Equal test; PC relative branch branch on not eq.bne $1,$2,100if ($1!= $2) go to PC Not equal test; PC relative set on less thanslt $1,$2,$3if ($2 < $3) $1=1; else $1=0 Compare less than; 2’s comp. set less than imm.slti $1,$2,100if ($2 < 100) $1=1; else $1=0 Compare < constant; 2’s comp. set less than uns.sltu $1,$2,$3if ($2 < $3) $1=1; else $1=0 Compare less than; natural numbers set l. t. imm. uns.sltiu $1,$2,100if ($2 < 100) $1=1; else $1=0 Compare < constant; natural numbers jumpj 10000go to Jump to target address jump registerjr $31go to $31 For switch, procedure return jump and linkjal 10000$31 = PC + 4; go to For procedure call

Enero 2004 Signed vs. Unsigned Comparison $1= 0… $2= 0… $3= 1… 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 = ;

Enero 2004 Miscellaneous MIPS I instructions " breakA breakpoint trap occurs, transfers control to exception handler " syscallA system trap occurs, transfers control to exception handler " coprocessor instrs.Support for floating point " TLB instructionsSupport for virtual memory " restore from exceptionRestores previous interrupt mask & kernel/user mode bits into status register " load word left/rightSupports misaligned word loads " store word left/rightSupports misaligned word stores

Enero 2004 SW conventions for MIPS registers 0zero constant 0 1atreserved for assembler 2v0expression evaluation & 3v1function results 4a0arguments 5a1 6a2 7a3 8t0temporary: caller saves...(callee can clobber) 15t7 16s0callee saves... (callee must save) 23s7 24t8 temporary (cont’d) 25t9 26k0reserved for OS kernel 27k1 28gpPointer to global area 29spStack pointer 30fpframe pointer 31raReturn Address (HW)

Enero 2004 Register zero always has the value zero (even if you try to write it) Branch/jump and link put the return addr. PC+4 or 8 into the link register (R31) (depends on logical vs physical architecture) All instructions change all 32 bits of the destination register (including lui, lb, lh) and all read all 32 bits of sources (add, sub, and, or, … ) Immediate arithmetic and logical instructions are extended as follows: logical immediates ops are zero extended to 32 bits arithmetic immediates ops are sign extended to 32 bits (including addu) The data loaded by the instructions lb and lh are extended as follows: lbu, lhu are zero extended lb, lh are sign extended Overflow can occur in these arithmetic and logical instructions: add, sub, addi it cannot occur in addu, subu, addiu, and, or, xor, nor, shifts, mult, multu, div, divu MIPS ISA details

Enero 2004 Peer Instruction: $s3=i, $s4=j, 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] addiu $s3,$s3,1# i = i + 1 slti $t1,$t0,10 # $t1 = $t0 < 10 beq $t1,$0, Loop # goto Loop slti $t1,$t0, 0 # $t1 = $t0 < 0 bne $t1,$0, Loop # goto Loop 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] = 10 || A[i++] = 10 || A[i] = 10 && A[i++] < 0 6 None of the above

Enero 2004 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.

Enero 2004 R-Format Instructions (1/4) " Define “fields” of the following number of bits each: = opcodersrtrdfunctshamt " For simplicity, each field has a name:

Enero 2004 R-Format Instructions (2/4) " What do these field integer values tell us?  opcode : partially specifies what instruction it is " Note: This number is equal to 0 for all R-Format instructions.  funct : combined with opcode, this number exactly specifies the instruction

Enero 2004 R-Format Instructions (3/4) " 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

Enero 2004 R-Format Instructions (4/4) " Final field:  shamt : This field contains the amount a shift instruction will shift by. Shifting a 32-bit word by more than 31 is useless, so this field is only 5 bits (so it can represent the numbers 0-31). – This field is set to 0 in all but the shift instructions.

Enero 2004 R-Format Example " MIPS Instruction: add $8,$9,$ Binary number per field representation: Decimal number per field representation: hex representation: 012A 4020 hex decimal representation: 19,546,144 ten hex

Enero 2004 I-Format Example (1/2) " MIPS Instruction: addi $21,$22,-50 opcode = 8 (look up in table in book) rs = 22 (register containing operand) rt = 21 (target register) immediate = -50 (by default, this is decimal)

Enero 2004 I-Format Example (2/2) " MIPS Instruction: addi $21,$22, Decimal/field representation: Binary/field representation: hexadecimal representation: 22D5 FFCE hex decimal representation: 584,449,998 ten

Enero 2004 J-Format Instructions (1/2) " Define “fields” of the following number of bits each: 6 bits26 bits opcodetarget address " As usual, each field has a name: " 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.

Enero 2004 J-Format Instructions (2/2) " Summary: – New PC = { PC[31..28], target address, 00 } " Understand where each part came from! " Note: {,, } means concatenation { 4 bits, 26 bits, 2 bits } = 32 bit address – { 1010, , 00 } =

Enero 2004 Peer Instruction opcodersrtoffset rdfunctshamt opcodersrt opcodersrtimmediate rdfunctshamt opcodersrt rdfunctshamt opcodersrt 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 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

Enero 2004 SPIM