Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania 18042 ECE 313 - Computer Organization Lecture 4 - Instruction.

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

Goal: Write Programs in Assembly
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.
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
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
Chapter 2 Instructions: Language of the Computer Part III.
CS2100 Computer Organisation MIPS Part III: Instruction Formats (AY2014/2015) Semester 2.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Warning! Unlike the previous lessons, for today's lesson you will have to listen, think and even understand (for the exam, of course). Individuals with.
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.
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.
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.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 3 - Instruction.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
11/02/2009CA&O Lecture 03 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE 313 – Microprocessor Organization Lecture 4 - Instruction.
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
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
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/
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization Instructions Language of The Computer (MIPS) 2.
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.
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 9 Binary Representation and Logical Operations.
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
Computer Organization Instruction Sets: MIPS Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann Publishers.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
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
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
CS170 Computer Organization and Architecture I
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Systems Architecture Lecture 5: MIPS Instruction Set
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Instruction encoding The ISA defines Format = Encoding
The University of Adelaide, School of Computer Science
Computer Architecture
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
Presentation transcript:

Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 4 - Instruction Sets: MIPS Fall 2004 Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann Publishers all rights reserved Tod Amon's COD2e Slides © 1998 Morgan Kaufmann Publishers all rights reserved Dave Patterson’s CS 152 Slides - Fall 1997 © UCB Rob Rutenbar’s Slides - Fall 1999 CMU other sources as noted Image Source: MIPS, Inc.

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS2 Outline - Instruction Sets  Instruction Set Overview  MIPS Instruction Set  Overview   Registers and Memory  MIPS Instructions  Software Concerns  Summary

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS3 MIPS Architecture - Applications  Embedded Applications - examples  Network Routers  Laser Printers  Digital Cameras  Game Consoles: Sony PS 2 / Nintendo 64  Personal Digital Assistants  Sony AIBO & QRIO Robots Image Source:

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS4 MIPS Design Principles 1. Simplicity Favors Regularity 2. Smaller is Faster 3. Good Design Makes Good Compromises 4. Make the Common Case Fast

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS5 Outline - Instruction Sets  Instruction Set Overview  MIPS Instruction Set  Overview  Registers and Memory   MIPS Instructions  Software Concerns  Summary

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS6 MIPS Registers and Memory Memory 4GB Max (Typically 64MB-1GB) 0x x x x C 0x x x x C 0xfffffff4 0xfffffffc PC = 0x C Registers 32 General Purpose Registers R0 R1 R2 R30 R31 32 bits

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS7 MIPS Registers  Fast access to program data  Register R0/$0/$zero : hardwired to constant zero  Register names:  $0-$31 or R0-R31  Specialized names based on usage convention $zero ($0) - always zero $s0-$s7 ($16-$23) - “saved” registers $t0-$t7 ($8-$15) - “temporary” registers $sp - stack pointer Other special-purpose registers

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS8 MIPS Registers and Usage

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS9 More about MIPS Memory Organization  Two views of memory:  2 32 bytes with addresses 0, 1, 2, …,  byte words* with addresses 0, 4, 8, …,  Both views use byte addresses  Word address must be multiple of 4 (aligned) 8 bits 0x x x x x x x x C 32 bits 0123 *Word sizes vary in other architectures Not all architectures require this

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS10 Outline - Instruction Sets  Instruction Set Overview  MIPS Instruction Set  Overview  Registers and Memory  MIPS Instructions   Software Concerns  Summary

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS11 MIPS Instructions  All instructions exactly 32 bits wide  Different formats for different purposes  Similarities in formats ease implementation oprsrtoffset 6 bits5 bits 16 bits oprsrtrdfunctshamt 6 bits5 bits 6 bits R-Format I-Format opaddress 6 bits26 bits J-Format

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS12 MIPS Instruction Types  Arithmetic & Logical - manipulate data in registers add $s1, $s2, $s3$s1 = $s2 + $s3 or $s3, $s4, $s5$s3 = $s4 OR $s5  Data Transfer - move register data to/from memory lw $s1, 100($s2)$s1 = Memory[$s ] sw $s1, 100($s2)Memory[$s ] = $s1  Branch - alter program flow beq $s1, $s2, 25if ($s1==$s1) PC = PC *25

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS13 MIPS Arithmetic & Logical Instructions  Instruction usage (assembly) add dest, src1, src2dest=src1 + src2 sub dest, src1, src2dest=src1 - src2 and dest, src1, src2dest=src1 AND src2  Instruction characteristics  Always 3 operands: destination + 2 sources  Operand order is fixed  Operands are always general purpose registers  Design Principles:  Design Principle 1: Simplicity favors regularity  Design Principle 2: Smaller is faster

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS14 Arithmetic Instruction Examples  C simple addition and assignment C code: A = B + C MIPS code:add $s0, $s1, $s2  Complex arithmetic assignment: C code:A = B + C + D; E = F - A; MIPS code:add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0  Compiler keeps track of mapping variables to registers (and, when necessary, memory)

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS15 Arithmetic & Logical Instructions - Binary Representation  Used for arithmetic, logical, shift instructions  op: Basic operation of the instruction (opcode)  rs: first register source operand  rt: second register source operand  rd: register destination operand  shamt: shift amount (more about this later)  funct: function - specific type of operation  Also called “R-Format” or “R-Type” Instructions oprsrtrdfunctshamt 6 bits5 bits 6 bits

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS16 oprsrtrdfunctshamt 6 bits5 bits 6 bits Decimal Binary Arithmetic & Logical Instructions - Binary Representation Example  Machine language for add $8, $17, $18  See reference card for op, funct values

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS17 MIPS Data Transfer Instructions  Transfer data between registers and memory  Instruction format (assembly) lw $dest, offset($addr)load word sw $src, offset($addr)store word  Uses:  Accessing a variable in main memory  Accessing an array element

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS18 Example - Loading a Simple Variable lw R5,8(R2) Memory 0x00 Variable Z = Variable X Variable Y 0x04 0x08 0x0c 0x10 0x14 0x18 0x1c 8 + Registers R0=0 (constant) R1 R2=0x10 R30 R31 R3 R4 R5 R2=0x10 R5 = Variable Z =

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS19 Data Transfer Example - Array Variable Registers R0=0 (constant) R1 R2=0x08 R30 R31 R3 R4 R5=105 C Program:int a[5]; a[3] = z; Assembly:sw $5,12($2) 12=0xc + Memory 0x00 a[0] a[4] a[2] a[1] a[3] 0x04 0x08 0x0c 0x10 0x14 0x18 0x1c Base Address R5=105 R2=0x08 a[3]=105 scaled offset

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS20 Data Transfer Instructions - Binary Representation  Used for load, store instructions  op: Basic operation of the instruction (opcode)  rs: first register source operand  rt: second register source operand  offset: 16-bit signed address offset (-32,768 to +32,767)  Also called “I-Format” or “I-Type” instructions oprsrtoffset 6 bits5 bits 16 bits Address source for sw destination for lw

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS21 I-Format vs. R-Format Instructions  Compare with R-Format offset 6 bits5 bits 16 bits I-Format oprsrtrdfunctshamt 6 bits5 bits 6 bits R-Format oprsrt Note similarity!

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS22 I-Format Example  Machine language for lw $9, 1200($8) == lw $t1, $1200($t0) oprsrtoffset 6 bits5 bits 16 bits Binary Decimal

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS23 MIPS Conditional Branch Instructions  Conditional branches allow decision making beq R1, R2, LABEL if R1==R2 goto LABEL bne R3, R4, LABEL if R3!=R4 goto LABEL  Example C Codeif (i==j) goto L1; f = g + h; L1:f = f - i; Assemblybeq $s3, $s4, L1 add $s0, $s1, $s2 L1:sub $s0, $s0, $s3

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS24 Example: Compiling C if-then-else  Example C Codeif (i==j) f = g + h; else f = g - h; Assemblybne $s3, $s4, Else add $s0, $s1, $s2 j Exit; # new: unconditional jump Else:sub $s0, $s0, $s3 Exit:  New Instruction: Unconditional jump j LABEL# goto Label

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS25 Binary Representation - Branch  Branch instructions use I-Format  offset is added to PC when branch is taken beq r0, r1, offset has the effect: if (r0==r1) pc = pc (offset << 2) else pc = pc + 4;  Offset is specified in instruction words (why?)  What is the range of the branch target addresses? oprsrtoffset 6 bits5 bits 16 bits Conversion to word offset

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS26 Branch Example  Machine language for beq $s3, $s4, L1 add $s0, $s1, $s2 L1:sub $s0, $s0, $s3 oprsrtoffset 6 bits5 bits 16 bits Binary Decimal $19 $20 PC PC+4 Target of beq 1-instruction offset

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS27 Comparisons - What about, >=?  bne, beq provide equality comparison  slt provides magnitude comparison slt $t0,$s3,$s4# if $s3<$s4 $t0=1; # else $t0=0;  Combine with bne or beq to branch: slt $t0,$s3,$s4# if (a<b) bne $t0,$zero, Less# goto Less;  Why not include a blt instruction in hardware?  Supporting in hardware would lower performance  Assembler provides this function if desired (by generating the two instructions) condition register

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS28 Binary Representation - Jump  Jump Instruction uses J-Format ( op=2 )  What happens during execution? PC = PC[31:28] : (IR[25:0] << 2) opaddress 6 bits26 bits Conversion to word offset Concatenate upper 4 bits of PC to form complete 32-bit address

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS29 Jump Example  Machine language for j L5 Assume L5 is at address 0x and PC <= 0x03FFFFFF Binary Decimal/Hex opaddress 6 bits26 bits 20x >>2 lower 28 bits 0x

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS30 Constants / Immediate Instructions  Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18;  MIPS Immediate Instructions (I-Format): addi $29, $29, 4 slti $8, $18, 10 andi $29, $29, 6 ori $29, $29, 4  Allows up to 16-bit constants  How do you load just a constant into a register? ori $5, $zero, 666 Arithmetic instructions sign-extend immed. Logical instructions don’t sign extend immed.

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS31 Why are Immediates only 16 bits?  Because 16 bits fits neatly in a 32-bit instruction  Because most constants are small (i.e. < 16 bits)  Design Principle 4: Make the Common Case Fast

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS32 MIPS Logical Instructions  and, andi - bitwise AND  or, ori - bitwise OR  Example and$s2,$s0,$s1 ori$s3,s2, $s0 $s1 $s $s ( )

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS33 Logical Operations - Applications  Masking - clear, set or test  Individual bits  Groups of bits

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS34 (original contents) $t0 Larger Constants  Immediate operations provide for 16-bit constants  What about when we need larger constants?  Use "load upper immediate - lui” (I-Format) lui $t0,  Then use ori to fill in lower 16 bits: ori $t0, $t0, filled with zeros $t

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS35 MIPS Shift Instructions  MIPS Logical Shift Instructions  Shift left: sll (shift-left logical) instruction  Right shift: srl (shift-right logical) instruction sll$s1,$s0,8 srl$s2,$s1, Zeros shift in Zeros shift in $s0 $s1 $s2

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS36 Shift Instruction Encodings  Applications  Bitfield access (see book)  Multiplication / Division by power of 2  Example: array access sll $t0,$t1,2 # $t0=$t1*4 add $t3,$t1,$t2 lw $t3, 0($t3) oprsrtrdfunctshamt 6 bits5 bits 6 bits srl 0rsrtrd0shamt sll 0rsrtrd6shamt unused

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS37 Summary - MIPS Instruction Set  Three instruction formats  Similarities in formats ease implementation oprsrtoffset 6 bits5 bits 16 bits oprsrtrdfunctshamt 6 bits5 bits 6 bits R-Format I-Format opaddress 6 bits26 bits J-Format

ECE 313 Fall 2004Lecture 4 - Instruction Sets: MIPS38 Instruction Sets - Overview  Instruction Set Overview  MIPS Instruction Set  Overview  Registers and Memory  Instructions  Software Concerns   Compiling C Constructs  Procedures (Subroutines) and Stacks  Example: Internet Worms  Compiling, Linking, and Loading  Example: String Processing / SPIM Demo