C OMPUTER A RCHITECTURE & O RGANIZATION MIPS Instruction Set Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology Taxila.

Slides:



Advertisements
Similar presentations
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Advertisements

10/9: Lecture Topics Starting a Program Exercise 3.2 from H+P Review of Assembly Language RISC vs. CISC.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
CS3350B Computer Architecture Winter 2015 Lecture 4
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review
CSE431 L02 MIPS ISA Review.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 02: MIPS ISA Review Mary Jane Irwin (
CSE331 W02.1Irwin&Li 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Adaptado a DSD. R. Pereira Section 1: Mary Jane Irwin (
331 Week 3. 1Spring 2005 Review: MIPS Organization Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
MIPS Architecture CPSC 321 Computer Architecture Andreas Klappenecker.
331 W02.1Spring 05 Announcements  HW1 is due on this Friday  Appendix A (on CD) is very helpful to HW1.
OK, we are now ready to begin Chapter 2 of our text
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
331 W02.1Fall 2003 Announcements  HW1 is due on this Friday (Sept 12 th )  Appendix A is very helpful to HW1. Check out system calls on Page A-48. 
331 Week 3. 1Fall 2003 Head’s Up  This week’s material l MIPS control flow operations (for, while, if-the-else, …) -Reading assignment - PH 3.5  Reminders.
ECE 4436ECE 5367 ISA I. ECE 4436ECE 5367 CPU = Seconds= Instructions x Cycles x Seconds Time Program Program Instruction Cycle CPU = Seconds= Instructions.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
331 Practice Exam.1Fall 2003 Naming Conventions for Registers 0$zero constant 0 (Hdware) 1$atreserved for assembler 2$v0expression evaluation & 3$v1function.
The MIPS 32 Our objective is to get an appreciation with: working with a “typical” computer machine language. programming in assembly language. debuging.
Lecture 4 section 2.4-?? As opposed to CISC – Complicated Instruction Set Architecture (ala the x86)
CS.305 Computer Architecture Computer Abstractions and Technology Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from.
CMPT 334 Computer Organization
CSE331 W03.1Irwin&Li Fall 2006 PSU CSE 331 Computer Organization and Design Fall 2006 Week 3 Section 1: Mary Jane Irwin (
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
CS224 Fall 2011 Chap 2a Computer Organization CS224 Fall 2011 Chapter 2 a With thanks to M.J. Irwin, D. Patterson, and J. Hennessy for some lecture slide.
CSE331 W02.1Irwin Fall 2001 PSU Computer Architecture Discussion Lecture # 2 MIPS Programming.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Lecture 8. MIPS Instructions #3 – Branch Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University 2010 R&E Computer System Education.
Computer Organization CS224 Fall 2012 Lessons 9 and 10.
1 Computer Architecture COSC 3430 Lecture 3: Instructions.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
CS Computer Architecture Spring 2006 Week 4 Paul Durand ( Course url:
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
CSIE30300 Computer Architecture Unit 02: MIPS ISA Review Hsin-Chou Chi [Adapted from material by and
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
CSE 340 Computer Architecture Spring 2014 MIPS ISA Review.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Digital Systems Design L02 MIPS ISA Review.1 Digital Systems Design Lecture 02: MIPS ISA Review Adapted from Mary Jane Irwin ( )
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
Computer Organization Rabie A. Ramadan Lecture 3.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CPE 232 MIPS ISA1 CPE 232 Computer Organization MIPS ISA Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin ( which.
Lecture 2: Instruction Set Architecture part 1 (Introduction) Mehran Rezaei.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
CSE 340 Computer Architecture Summer 2016 MIPS ISA Review.
CS35101 Computer Architecture Spring 2006 Week 2.
Computer Architecture Instruction Set Architecture
Instructions: Language of the Computer
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
Computer Architecture
Computer Architecture
CS352H Computer Systems Architecture
Presentation transcript:

C OMPUTER A RCHITECTURE & O RGANIZATION MIPS Instruction Set Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology Taxila. 19/2/2009 CA&O Lecture 6 by Engr. Umbreen Sabir 1

( VON N EUMANN ) P ROCESSOR O RGANIZATION  Control needs to 1. input instructions from Memory 2. issue signals to control the information flow between the Datapath components and to control what operations they perform 3. control instruction sequencing 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir Fetch DecodeExec CPU Control Datapath MemoryDevices Input Output  Datapath needs to have the l components – the functional units and storage (e.g., register file) needed to execute instructions l interconnects - components connected so that the instructions can be accomplished and so that data can be loaded from and stored to Memory

For a given level of function, however, that system is best in which one can specify things with the most simplicity and straightforwardness. … Simplicity and straightforwardness proceed from conceptual integrity. … Ease of use, then, dictates unity of design, conceptual integrity. The Mythical Man-Month, Brooks, pg 44 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir

RISC-R EDUCED I NSTRUCTION S ET C OMPUTER  RISC philosophy  fixed instruction lengths  load-store instruction sets  limited addressing modes  limited operations  MIPS, Sun SPARC, HP PA-RISC, IBM PowerPC, Intel (Compaq) Alpha, …  Instruction sets are measured by how well compilers use them as opposed to how well assembly language programmers use them 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir Design goals: speed, cost (design, fabrication, test, packaging), size, power consumption, reliability, memory space (embedded systems)

MIPS I NSTRUCTION S ET A RCHITECTURE  Instruction Categories  Computational  Load/Store  Jump and Branch  Floating Point  coprocessor  Memory Management  Special 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir R0 - R31 PC HI LO Registers OP rs rt rdsafunct rs rt immediate jump target 3 Instruction Formats: all 32 bits wide R format I format J format

U NSIGNED B INARY R EPRESENTATION HexBinaryDecimal 0x … x … x … x … x … x … x … x … x … x …10019 … 0xFFFFFFFC1…1100 0xFFFFFFFD1…1101 0xFFFFFFFE1…1110 0xFFFFFFFF1… bit bit position bit weight

A SIDE : B EYOND N UMBERS American Std Code for Info Interchange (ASCII): 8-bit bytes representing characters 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir ASCIICharASCIICharASCIICharASCIICharASCIICharASCIIChar 133!49165A97a113q 234“50266B98b114r 335#51367C99c115s 4EOT36$52468D100d116t 537%53569E101e117u 6ACK38&54670F102f118v 739‘55771G103g119w 8bksp40(56872H104h120x 9tab41)57973I105i121y 10LF42*58:74J106j122z ;75K107k123{ 12FF44,60<76L108l124| 1547/63?79O111o127DEL

MIPS A RITHMETIC I NSTRUCTIONS  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  Each arithmetic instruction performs only one operation  Each arithmetic instruction fits in 32 bits and specifies exactly three operands destination  source1 op source2  Those operands are all contained in the datapath’s register file ( $t0,$s1,$s2 ) – indicated by $  Operand order is fixed (destination first)

MIPS A RITHMETIC I NSTRUCTIONS  MIPS assembly language arithmetic statement add$t0, $s1, $s2 sub$t0, $s1, $s2 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  Each arithmetic instruction performs only one operation  Each arithmetic instruction fits in 32 bits and specifies exactly three operands destination  source1 op source2  Each arithmetic instruction performs only one operation  Each arithmetic instruction fits in 32 bits and specifies exactly three operands destination  source1 op source2  Operand order is fixed (destination first)  Those operands are all contained in the datapath’s register file ( $t0,$s1,$s2 ) – indicated by $

A SIDE : MIPS R EGISTER C ONVENTION NameRegister Number UsagePreserve on call? $zero0constant 0 (hardware)n.a. $at1reserved for assemblern.a. $v0 - $v12-3returned valuesno $a0 - $a34-7argumentsyes $t0 - $t78-15temporariesno $s0 - $s716-23saved valuesyes $t8 - $t924-25temporariesno $gp28global pointeryes $sp29stack pointeryes $fp30frame pointeryes $ra31return addr (hardware)yes

MIPS R EGISTER F ILE  Holds thirty-two 32-bit registers  Two read ports and  One write port 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 locations  Registers are l Faster than main memory -But register files with more locations are slower (e.g., a 64 word file could be as much as 50% slower than a 32 word file) -Read/write port increase impacts speed quadratically l Easier for a compiler to use -e.g., (A*B) – (C*D) – (E*F) can do multiplies in any order vs. stack l Can hold variables so that -code density improves (since register are named with fewer bits than a memory location) write control

M ACHINE L ANGUAGE - A DD I NSTRUCTION  Instructions, like registers and words of data, are 32 bits long  Arithmetic Instruction Format (R format): add $t0,$s1,$s2 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt rd shamt funct op6-bitsopcode that specifies the operation rs5-bitsregister file address of the first source operand rt5-bitsregister file address of the second source operand rd5-bitsregister file address of the result’s destination shamt5-bitsshift amount (for shift instructions) funct6-bitsfunction code augmenting the opcode

MIPS M EMORY A CCESS I NSTRUCTIONS  MIPS has two basic data transfer instructions for accessing memory lw$t0, 4($s3) #load word from memory sw$t0, 8($s3) #store word to memory  The data is loaded into (lw) or stored from (sw) a register in the register file – a 5 bit address  The memory address – a 32 bit address – is formed by adding the contents of the base address register to the offset value  A 16-bit field meaning access is limited to memory locations within a region of  2 13 or 8,192 words (  2 15 or 32,768 bytes) of the address in the base register  Note that the offset can be positive or negative 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir

M ACHINE L ANGUAGE - L OAD I NSTRUCTION Load/Store Instruction Format (I format): lw $t0, 24($s2) 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt 16 bit offset Memory dataword address (hex) 0x x x x c 0xf f f f f f f f $s2 0x $s2 = = 0x120040ac $t0

B YTE A DDRESSES  Since 8-bit bytes are so useful, most architectures address individual bytes in memory  The memory address of a word must be a multiple of 4 (alignment restriction)  Big Endian: leftmost byte is word address IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA  Little Endian:rightmost byte is word address Intel 80x86, DEC Vax, DEC Alpha (Windows NT) 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir msblsb little endian byte big endian byte 0

A SIDE : L OADING AND S TORING B YTES  MIPS provides special instructions to move bytes lb$t0, 1($s3) #load byte from memory sb$t0, 6($s3) #store byte to memory 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt 16 bit offset  What 8 bits get loaded and stored? l load byte places the byte from memory in the rightmost 8 bits of the destination register -what happens to the other bits in the register? l store byte takes the byte from the rightmost 8 bits of a register and writes it to a byte in memory -what happens to the other bits in the memory word?

MIPS C ONTROL F LOW I NSTRUCTIONS  MIPS conditional branch instructions: bne $s0, $s1, Lbl#go to Lbl if $s0  $s1 beq $s0, $s1, Lbl#go to Lbl if $s0=$s1  Ex: if (i==j) h = i + j; bne $s0, $s1, Lbl1 add $s3, $s0, $s1 Lbl1:... 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  Instruction Format (I format): op rs rt 16 bit offset  How is the branch destination address specified?

S PECIFYING B RANCH D ESTINATIONS  Use a register (like in lw and sw) added to the 16-bit offset  which register? Instruction Address Register (the PC)  its use is automatically implied by instruction  PC gets updated (PC+4) during the fetch cycle so that it holds the address of the next instruction  limits the branch distance to to instructions from the (instruction after the) branch instruction, but most branches are local anyway 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir PC Add 32 offset sign-extend from the low order 16 bits of the branch instruction branch dst address ? Add 4 32

M ORE B RANCH I NSTRUCTIONS  We have beq, bne, but what about other kinds of brances (e.g., branch-if-less-than)? For this, we need yet another instruction, slt  Set on less than instruction: slt $t0, $s0, $s1 # if $s0 < $s1 then # $t0 = 1else # $t0 = 0  Instruction format (R format): 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir 2 op rs rt rd funct

M ORE B RANCH I NSTRUCTIONS, C ON ’ T  Can use slt, beq, bne, and the fixed value of 0 in register $zero to create other conditions  less than blt $s1, $s2, Label  less than or equal to ble $s1, $s2, Label  greater than bgt $s1, $s2, Label  great than or equal to bge $s1, $s2, Label 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir slt $at, $s1, $s2#$at set to 1 if bne $at, $zero, Label# $s1 < $s2  Such branches are included in the instruction set as pseudo instructions - recognized (and expanded) by the assembler Its why the assembler needs a reserved register ( $at )

O THER C ONTROL F LOW I NSTRUCTIONS  MIPS also has an unconditional branch instruction or jump instruction: j label#go to label 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  Instruction Format (J Format): op 26-bit address PC from the low order 26 bits of the jump instruction

A SIDE : B RANCHING F AR A WAY  What if the branch destination is further away than can be captured in 16 bits? 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  The assembler comes to the rescue – it inserts an unconditional jump to the branch target and inverts the condition beq$s0, $s1, L1 becomes bne$s0, $s1, L2 jL1 L2:

I NSTRUCTIONS FOR P ROCEDURES A CCESS MIPS procedure call instruction: jalProcedureAddress#jump and link Saves PC+4 in register $ra to have a link to the next instruction for the procedure return Machine format (J format) Then can do procedure return with a jr$ra#return Instruction format (R format): 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op 26 bit address op rs funct

A SIDE : S PILLING R EGISTERS  What if the callee needs more registers? What if the procedure is recursive?  uses a stack – a last-in-first-out queue – in memory for passing additional values or saving (recursive) return address(es) 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir  One of the general registers, $sp, is used to address the stack (which “grows” from high address to low address) l add data onto the stack – push $sp = $sp – 4 data on stack at new $sp l remove data from the stack – pop data from stack at $sp $sp = $sp + 4 low addr high addr $sptop of stack

MIPS I MMEDIATE I NSTRUCTIONS Addi $sp,$sp,4 #$sp = $sp + 4 slti $t0,$s2,15 #$t0 = 1 if $s2<15 Machine format (I format): 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt 16 bit immediate I format  Small constants are used often in typical code  Possible approaches? l put “typical constants” in memory and load them l create hard-wired registers (like $zero) for constants like 1 l have special instructions that contain constants !  The constant is kept inside the instruction itself! l Immediate format limits values to the range –1 to -2 15

A SIDE : H OW A BOUT L ARGER C ONSTANTS ? We'd also be able to load a 32 bit constant into a register, for this we must use two instructions a new "load upper immediate" instruction lui $t0, Then must get the lower order bits right, use ori $t0, $t0, /2/ CA&O Lecture 6 by Engr. Umbreen Sabir

MIPS O RGANIZATION S O F AR 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir Processor Memory 32 bits 2 30 words read/write addr read data write data word address (binary) 0…0000 0…0100 0…1000 0…1100 1…1100 Register File src1 addr src2 addr dst addr write data 32 bits src1 data src2 data 32 registers ($zero - $ra) PC ALU byte address (big Endian) Fetch PC = PC+4 DecodeExec Add 32 4 Add 32 branch offset

MIPS ISA S O F AR CategoryInstrOp CodeExampleMeaning Arithmetic (R & I format) add0 and 32add $s1, $s2, $s3$s1 = $s2 + $s3 subtract0 and 34sub $s1, $s2, $s3$s1 = $s2 - $s3 add immediate8addi $s1, $s2, 6$s1 = $s2 + 6 or immediate13ori $s1, $s2, 6$s1 = $s2 v 6 Data Transfer (I format) load word35lw $s1, 24($s2)$s1 = Memory($s2+24) store word43sw $s1, 24($s2)Memory($s2+24) = $s1 load byte32lb $s1, 25($s2)$s1 = Memory($s2+25) store byte40sb $s1, 25($s2)Memory($s2+25) = $s1 load upper imm15lui $s1, 6$s1 = 6 * 2 16 Cond. Branch (I & R format) br on equal4beq $s1, $s2, Lif ($s1==$s2) go to L br on not equal5bne $s1, $s2, Lif ($s1 !=$s2) go to L set on less than0 and 42slt $s1, $s2, $s3if ($s2<$s3) $s1=1 else $s1=0 set on less than immediate 10slti $s1, $s2, 6if ($s2<6) $s1=1 else $s1=0 Uncond. Jump (J & R format) jump2j 2500go to jump register0 and 8jr $t1go to $t1 jump and link3jal 2500go to 10000; $ra=PC+4

MIPS O PERAND A DDRESSING M ODES  Register addressing – operand is in a register  Base (displacement) addressing – operand is at the memory location whose address is the sum of a register and a 16-bit constant contained within the instruction  Register relative (indirect) with 0($a0)  Pseudo-direct with addr($zero)  Immediate addressing – operand is a 16-bit constant contained within the instruction 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt rd funct Register word operand base register op rs rt offset Memory word or byte operand op rs rt operand

MIPS I NSTRUCTION A DDRESSING M ODES  PC-relative addressing –instruction address is the sum of the PC and a 16-bit constant contained within the instruction  Pseudo-direct addressing – instruction address is the 26- bit constant contained within the instruction concatenated with the upper 4 bits of the PC 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir op rs rt offset Program Counter (PC) Memory branch destination instruction op jump address Program Counter (PC) Memory jump destination instruction||

MIPS (RISC) D ESIGN P RINCIPLES  Simplicity favors regularity  fixed size instructions – 32-bits  small number of instruction formats  opcode always the first 6 bits  Good design demands good compromises  three instruction formats  Smaller is faster  limited instruction set  limited number of registers in register file  limited number of addressing modes  Make the common case fast  arithmetic operands from the register file (load-store machine)  allow instructions to contain immediate operands 19/2/ CA&O Lecture 6 by Engr. Umbreen Sabir