CS352H Computer Systems Architecture

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

CS/COE0447 Computer Organization & Assembly Language
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Informationsteknologi Saturday, September 29, 2007 Computer Architecture I - Class 41 Today’s class More assembly language programming.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
MIPS Overview (with comparisons to x86)
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
ENEE350 Spring07 1 Ankur Srivastava University of Maryland, College Park Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005.”
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
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.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
83 Assembly Language Readings: Chapter 2 ( , 2.8, 2.9, 2.13, 2.15), Appendix A.10 Assembly language Simple, regular instructions – building blocks.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
MIPS Instructions Instructions: Language of the Machine
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
MIPS Instructions Instructions: Language of the Machine
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
EEL5708/Bölöni Lec 3.1 Fall 2006 Sept 1, 2006 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
CDA 3101 Spring 2016 Introduction to Computer Organization
Pirouz Bazargan SabetDecember 2003 Effective Implementation of a 32-bit RISC Processor Pirouz Bazargan Sabet University of Paris 6 - LIP6 - ASIM
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Digital Logic Design Alex Bronstein
MIPS Assembly.
/ Computer Architecture and Design
Computer Architecture Instruction Set Architecture
Computer Organization and Design Instruction Sets - 2
Instructions: Language of the Computer
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
32-bit MIPS ISA.
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Computer Organization and Design Instruction Sets
ECE/CS 552: Instruction Sets – MIPS
Instructions - Type and Format
Appendix A Classifying Instruction Set Architecture
Lecture 4: MIPS Instruction Set
MPIS Instructions Functionalities of instructions Instruction format
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Today’s Lecture Quick Review of Last Lecture
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
Computer Instructions
Computer Architecture
Flow of Control -- Conditional branch instructions
Instruction encoding The ISA defines Format = Encoding
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Instruction encoding The ISA defines Format = Encoding
CSC3050 – Computer Architecture
MIPS Instruction Set Architecture
Flow of Control -- Conditional branch instructions
Instruction encoding The ISA defines Format = Encoding
Reduced Instruction Set Computer (RISC)
MIPS Arithmetic and Logic Instructions
MIPS Arithmetic and Logic Instructions
Presentation transcript:

CS352H Computer Systems Architecture Lecture 2: Instruction Set Architectures I September 1, 2009

ISA is a Contract Between the programmer and the hardware: Defines visible state of the system Defines how the state changes in response to instructions Programmer obtains a model of how programs will execute Hardware designer obtains a formal definition of the correct way to execute instructions ISA Specification: Instruction set How instructions modify the state of the machine Binary representation Today: MIPS ISA University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 2

ISA is a Contract Between the programmer and the hardware: Defines visible state of the system Defines how the state changes in response to instructions Programmer obtains a model of how programs will execute Hardware designer obtains a formal definition of the correct way to execute instructions ISA Specification: Instruction set How instructions modify the state of the machine Binary representation Today: MIPS ISA University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 3

ISA Specification Instruction Representation Instruction formats Instruction types Addressing modes Data types Operations Interrupts/Events Machine state Memory organization Register organization University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 4

MIPS ISA 32 GP registers (R0-R31) – 32 bits each 32 FP registers (F0-F31) – 32 bits each 16 double-precision (using adjacent 32-bit registers) 8-, 16-, and 32-bit integer & 32- and 64-bit floating point data types Load/Store architecture (no memory access in ALU ops) A few, simple addressing modes: Immediate: R1  0x21 Displacement: R1  0x100(R2) Simple fixed instruction format Three types <100 instructions Fused compare and branch Pseudo instructions Designed for pipelining and ease of compilation University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 5

MIPS ISA: A Visual Instruction Categories Registers Memory Computational Load/Store Jump and Branch Floating Point Memory Management Special R0 - R31 PC HI LO 32 32 3 Instruction Formats: all 32 bits wide OP rs rt rd shamt funct R format I format OP rs rt immediate OP jump target J format University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 6 6

MIPS Register Convention Name Register Number Usage Preserve on call? $zero constant 0 (hardware) n.a. $at 1 reserved for assembler $v0 - $v1 2-3 returned values no $a0 - $a3 4-7 arguments yes $t0 - $t7 8-15 temporaries $s0 - $s7 16-23 saved values $t8 - $t9 24-25 $k0 - $k1 26-27 reserved for interrupts/traps $gp 28 global pointer $sp 29 stack pointer $fp 30 frame pointer $ra 31 return addr (hardware) University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 7

MIPS Arithmetic Instructions Example Meaning Comment add add $8, $9, $10 $8 = $9 + $10 3 opnds; Exception possible subtract sub $8, $9, $10 $8 = $9 - $10 add immediate addi $8, $9, 100 $8 = $9 + 100 + const; Exception possible add unsigned addu $8, $9, $10 3 opnds; No exception subtract unsigned subu $8, $9, $10 add imm. Unsig. addiu $8, $9, 100 + const; No exception multiply mult $8, $9 Hi,Lo = $8 * $9 64-bit signed product multiply unsigned multu $8, $9 64-bit unsigned product divide div $8, $9 Lo = $8 $9 Hi = $8 mod $9 Lo = quotient Hi = remainder divide unsigned divu $8, $9 Unsigned quotient & remainder move from Hi mfhi $8 $8 = Hi move from Lo mflo $8 $8 = Lo Which add for address arithmetic? Which for integers? University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 8

Multiply & Divide Start multiply/Divide Move result from Hi or Lo mult rs, rt multu rs, rt div rs, rt divu rs, rt Move result from Hi or Lo mfhi rd mflo rd Move to Hi or Lo (Why?) mthi rd mtlo rd University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 9

MIPS Logical Instructions Example Meaning Comment and and $8, $9, $10 $8 = $9 & $10 3 opnds; Logical AND or or $8, $9, $10 $8 = $9 | $10 3 opnds; Logical OR xor xor $8, $9, $10 $8 = $9  $10 + const; Logical XOR nor nor $8, $9, $10 $8 = ~($9 | $10) 3 opnds; Logical NOR and immediate andi $8, $9, 10 $8 = $9 & 10 Logical AND; Reg, Const or immediate ori $8, $9, 10 $8 = $9 | 10 Logical OR; Reg, Const shift left logical sll $8, $9, 10 $8 = $9 << 10 Shift left by constant shift right logical srl $8, $9, 10 $8 = $9 >> 10 Shift right by constant shift right arith. sra $8, $9, 10 Const srl with sign extension sllv $8, $9, $10 $8 = $9 << $10 Shift left by variable srlv $8, $9, $10 $8 = $9 >> $10 Shift right by variable srav $8, $9, $10 Var. srl with sign extension University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 10

Byte Addresses 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) Nowadays endian-ness is configurable msb lsb 3 2 1 0 little endian byte 0 0 1 2 3 big endian byte 0 Talk about the reasons (performance) for the word/byte alignment restriction University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 11 11

MIPS Data Transfer Instructions Example Meaning load word lw $8, 100($9) $8 = Mem[$9 + 100] load half word lh $8, 102($9) $8 = Mem[$9 + 102] load half word unsigned lhu $8, 102($9) load byte lb $8, 103($9) $8 = Mem[$9 + 103] load byte unsigned lbu $8, 103($9) load upper immediate lui $8, 47 Upper 16 bits of $8 = 47 store word sw $8, 100($9) Mem[$9 + 100] = $8 store half word sh $8, 102($9) Mem[$9 + 102] = $8 store byte sb $8, 103($9) Mem[$9 + 103] = $8 Where do half words & bytes get placed on lh & lb? What happens to the rest of the word on sb? University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 12

MIPS 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 > bltz < bgez >= bltzal rs, offset if R[rs] < 0 then branch and link (into R31) bgezal >= Remaining compare and branches take two instructions Almost all comparisons are against zero Hence $0 is always 0! University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 13

MIPS Jump, Branch & Compare Instructions Example Meaning branch on equal beq $8, $9, 100 If ($8 == $9) goto PC+4+100 branch on not equal bne $8, $9, 100 If ($8 != $9) goto PC+4+100 set on less than slt $8, $9, $10 If ($9 < $10) then $8 = 1 else $8 = 0; set less than immed. slti $8, $9, 100 If ($9 < 100) then $8 = 1 else $8 = 0; set less than unsig. sltu $8, $9, $10 set less than immed. unsig. sltiu $8, $9, 100 jump j 10004 goto 10004 jump register jr $31 goto $31 jump and link jal 10004 $31 = PC + 4; goto 10004 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 14

Procedure Support Caller Callee Preserved state Not preserved Save $t0 - $t9, if needed Save $fp Push arguments on stack (and leave in $a0-$a3) Set $fp to point to arg’s Adjust $sp jal Callee Save $s0-$s7, $ra as needed Get arg’s Do its thing Put return values in $v0, $v1 jr $ra Preserved state $s0 - $s7 $sp $ra Not preserved $t0 - $t9 $a0 - $a3 $v0, $v1 … jal foo Return here University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 15

Machine Language: R-format R format instructions: three operands add $t0, $s1, $s2 op rs rt rd shamt funct op 6-bits opcode that specifies the operation rs 5-bits register file address of the first source operand rt 5-bits register file address of the second source operand rd 5-bits register file address of the result’s destination shamt 5-bits shift amount (for constant shift instructions) funct 6-bits function code augmenting the opcode University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 16

Machine Language: I-format I-format Instructions: Load/store Branches Arithmetic with an immediate operand lw $t0, 24($s2) op rs rt 16 bit offset beq $t0, $s2, offset op 6-bits opcode that specifies the operation rs 5-bits register file address of the first source operand rt 5-bits register file address of the second source operand offset 16-bits a constant value University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 17

Machine Language: J-format J-format instructions: Jump Jump and Link op 26-bit address What about Jump Register? University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 18

MIPS Operand Addressing Modes 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 op rs rt rd funct Register word operand base register op rs rt offset Memory word or byte operand op rs rt operand University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 19

MIPS Instruction Addressing Modes 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 op rs rt offset Program Counter (PC) Memory branch destination instruction op jump address Program Counter (PC) Memory jump destination instruction || University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 20

MIPS Organization So Far Processor Memory Register File 1…1100 src1 addr src1 data 5 32 src2 addr 32 registers ($zero - $ra) 5 dst addr read/write addr 5 src2 data write data 32 230 words 32 32 32 bits branch offset read data 32 Add PC 32 32 32 32 Add 32 4 write data 0…1100 Fetch PC = PC+4 32 0…1000 32 4 5 6 7 0…0100 32 ALU 1 2 3 0…0000 Exec Decode 32 word address (binary) 32 bits 32 byte address (big Endian) University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 21 21

MIPS (RISC) Design Principles 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 University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 22

Next Lecture ISA Principles ISA Evolution Make sure you’re comfortable with the contents of Ch. 2 You will need to read Appendix B to do the programming part of the assignment University of Texas at Austin CS352H - Computer Systems Architecture Fall 2009 Don Fussell 23