Systems Architecture Lecture 5: MIPS Instruction Set

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Instruction Set-Intro
Lecture 5: MIPS Instruction Set
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
Lec 12Systems Architecture1 Systems Architecture Lecture 12: Design of the MIPS ALU Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
CS3350B Computer Architecture Winter 2015 Lecture 4
Chapter 2 Instructions: Language of the Computer
Chapter 2.
1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
1  1998 Morgan Kaufmann Publishers Chapter 3 Text in blue is by N. Guydosh Updated 1/27/04 Instructions: Language of the Machine.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Chapter 2 Instructions: Language of the Computer Part I.
Computer Organization and Architecture Instructions: Language of the Machine Hennessy Patterson 2/E chapter 3. Notes are available with photocopier 24.
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
Oct. 25, 2000Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Alternative Instruction Sets * Jeremy R. Johnson Wed. Oct. 25, 2000.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
CHAPTER 6 Instruction Set Architecture 12/7/
 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.
EE472 – Spring 2007P. Chiang, with Slide Help from C. Kozyrakis (Stanford) ECE472 Computer Architecture Lecture #3—Oct. 2, 2007 Patrick Chiang TA: Kang-Min.
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
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
1  1998 Morgan Kaufmann Publishers Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow.
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
COMPUTER ARCHITECTURE & OPERATIONS I
Instruction Set Architecture
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
MIPS Assembly.
CS170 Computer Organization and Architecture I
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Systems Architecture Lecture 5: MIPS Instruction Set
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
The University of Adelaide, School of Computer Science
Computer Instructions
Computer Architecture
September 17 Test 1 pre(re)view Fang-Yi will demonstrate Spim
3.
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
COMS 361 Computer Organization
CPU Structure CPU must:
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Instruction Set Architecture
Presentation transcript:

Systems Architecture Lecture 5: MIPS Instruction Set September 4, 1997 Systems Architecture Lecture 5: MIPS Instruction Set Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all figures from Computer Organization and Design: The Hardware/Software Approach, Third Edition, by David Patterson and John Hennessy, are copyrighted material (COPYRIGHT 2004 MORGAN KAUFMANN PUBLISHERS, INC. ALL RIGHTS RESERVED). Lec 5 Systems Architecture

September 4, 1997 Introduction Objective: To introduce the MIPS instruction set and to show how MIPS instructions are represented in the computer. The stored-program concept: Instructions are represented as numbers. Programs can be stored in memory to be read or written just like data. Lec 5 Systems Architecture

Instructions Language of the machine September 4, 1997 Instructions Language of the machine More primitive than higher level languages (e.g. C, C++, Java) e.g. no sophisticated control flow , primitive data structures MIPS – ISA developed in the early 80’s (RISC) Similar to other RISC architectures developed since the 1980's Almost 100 million MIPS processors manufactured in 2002 Used by NEC, Nintendo, Cisco, Silicon Graphics, Sony, … Regular (32 bit instructions, small number of different formats) Relatively small number of instructions Register architecture (all instructions operate on registers) Load/Store architecture (memory accessed only with load/store instructions, with few addressing modes) Design goals: maximize performance and minimize cost, reduce processor design time Lec 5 Systems Architecture

MIPS Processor is popular September 4, 1997 MIPS Processor is popular Lec 5 Systems Architecture

Gadgets shipped with MIPS cores September 4, 1997 Gadgets shipped with MIPS cores Cable Modems 94% DSL Modems 40% VDSL Modems 93% IDTV 40% Cable STBs 76% DVD Recorder 75% Game Consoles 76% Office Automation 48% Color Laser Printers 62% Commercial Color Copiers 73% Source: Website of MIPS Technologies, Inc., 2004. Lec 5 Systems Architecture

MIPS Arithmetic All arithmetic instructions have 3 operands September 4, 1997 MIPS Arithmetic All arithmetic instructions have 3 operands Operand order is fixed (destination first) Example C code: A = B + C MIPS code: add $s0, $s1, $s2 (associated with variables by compiler) Using the natural number of operands for an operation (e.g. addition) conforms to the design principle of keeping the hardware simple. Lec 5 Systems Architecture

September 4, 1997 Temporary Variables Regularity of instruction format requires that expressions get mapped to a sequence of binary operations with temporary results being stored in temporary variables. Example C code: f = (g + h) - (i + j); Assume f, g, h, i, j are in $s0 through $s4 respectively MIPS code: add $t0, $s1, $s2 # $t0 = g+h add $t1, $s3, $s4 # $t1 = i+j sub $s0, $t0, $t1 # f = $t0 - $t1 Lec 5 Systems Architecture

September 4, 1997 Registers vs. Memory Operands for arithmetic instructions must be registers, — only 32 integer registers are available Compiler associates variables with registers When too many variable are used to fit in 32 registers, the compiler must allocate temporary space in memory and then load and store temporary results to/from memory. The compiler tries to put most frequently occurring variables in registers. The extra temporary variables must be “spilled” to memory. Lec 5 Systems Architecture

Chapter 2 — Instructions: Language of the Computer September 4, 1997 Memory Operands Main memory used for composite data Arrays, structures, dynamic data To apply arithmetic operations Load values from memory into registers Store result from register to memory Memory is byte addressed Each address identifies an 8-bit byte Words are aligned in memory Address must be a multiple of 4 MIPS is Big Endian Most-significant byte at least address of a word c.f. Little Endian: least-significant byte at least address 11 April 2017 Chapter 2 — Instructions: Language of the Computer

Load and Store All arithmetic instructions operate on registers September 4, 1997 Load and Store All arithmetic instructions operate on registers Memory is accessed through load and store instructions An example C code: A[12] = h + A[8]; Assume that $s3 contains the base address of A MIPS code: lw $t0, 32($s3) add $t0, $t0, $s2 sw $t0, 48($s3) Note: sw (store word instruction) has destination last. Note: remember arithmetic operands are registers, not memory! This is invalid: add 48($s3), $s2, 32($s3) Lec 5 Systems Architecture

Our First Example Can we figure out the code? swap(int v[], int k) September 4, 1997 September 4, 1997 Our First Example Can we figure out the code? swap(int v[], int k) { int temp; temp = v[k] v[k] = v[k+1]; v[k+1] = temp; } swap: sll $2, $5, 2 add $2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 Lec 5 Systems Architecture 14

Chapter 2 — Instructions: Language of the Computer September 4, 1997 The Constant Zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten Useful for common operations E.g., move between registers add $t2, $s1, $zero 11 April 2017 Chapter 2 — Instructions: Language of the Computer

Chapter 2 — Instructions: Language of the Computer September 4, 1997 §2.6 Logical Operations Logical Operations Instructions for bitwise manipulation Operation C Java MIPS Shift left << sll Shift right >> >>> srl Bitwise AND & and, andi Bitwise OR | or, ori Bitwise NOT ~ nor Useful for extracting and inserting groups of bits in a word 11 April 2017 Chapter 2 — Instructions: Language of the Computer

Chapter 2 — Instructions: Language of the Computer September 4, 1997 AND Operations Useful to mask bits in a word Select some bits, clear others to 0 and $t0, $t1, $t2 $t2 0000 0000 0000 0000 0000 1101 1100 0000 $t1 0000 0000 0000 0000 0011 1100 0000 0000 $t0 0000 0000 0000 0000 0000 1100 0000 0000 11 April 2017 Chapter 2 — Instructions: Language of the Computer

Chapter 2 — Instructions: Language of the Computer September 4, 1997 OR Operations Useful to include bits in a word Set some bits to 1, leave others unchanged or $t0, $t1, $t2 $t2 0000 0000 0000 0000 0000 1101 1100 0000 $t1 0000 0000 0000 0000 0011 1100 0000 0000 $t0 0000 0000 0000 0000 0011 1101 1100 0000 11 April 2017 Chapter 2 — Instructions: Language of the Computer

Chapter 2 — Instructions: Language of the Computer September 4, 1997 NOT Operations Useful to invert bits in a word Change 0 to 1, and 1 to 0 MIPS has NOR 3-operand instruction a NOR b == NOT ( a OR b ) nor $t0, $t1, $zero Register 0: always read as zero $t1 0000 0000 0000 0000 0011 1100 0000 0000 $t0 1111 1111 1111 1111 1100 0011 1111 1111 11 April 2017 Chapter 2 — Instructions: Language of the Computer

September 4, 1997 September 4, 1997 So far we’ve learned: MIPS — loading words but addressing bytes — arithmetic on registers only Instruction Meaning add $s1, $s2, $s3 $s1 = $s2 + $s3 sub $s1, $s2, $s3 $s1 = $s2 – $s3 lw $s1, 100($s2) $s1 = Memory[$s2+100] sw $s1, 100($s2) Memory[$s2+100] = $s1 Lec 5 Systems Architecture 21

Addressing in Jumps J format format (jump format – j, jal) op address September 4, 1997 Addressing in Jumps J format format (jump format – j, jal) Example: j 10000 op address 6-bits 26-bits 2 10000 6-bits 26-bits Lec 5 Systems Architecture

Target Addressing Example September 4, 1997 Target Addressing Example Loop code example Assume Loop at location 80000 Loop: sll $t1, $s3, 2 80000 19 9 2 add $t1, $t1, $s6 80004 22 32 lw $t0, 0($t1) 80008 35 8 bne $t0, $s5, Exit 80012 5 21 addi $s3, $s3, 1 80016 1 j Loop 80020 20000 Exit: … 80024 11 April 2017 Chapter 2 — Instructions: Language of the Computer

September 4, 1997 No-Op Instructions What would you expect a no-op instruction to be in binary? What is this in assembly? 11 April 2017 Systems Architecture

Design Principles Simplicity favors regularity Smaller is faster September 4, 1997 Design Principles Simplicity favors regularity All instructions 32 bits All instructions have 3 operands Smaller is faster Only 32 registers Good design demands good compromises All instructions are the same length Limited number of instruction formats: R, I, J Make common cases fast 16-bit immediate constant Only two branch instructions Lec 5 Systems Architecture