ECE232: Hardware Organization and Design

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
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.
ELEN 468 Advanced Logic Design
Chapter 2 Instructions: Language of the Computer
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
Prof. John Nestor ECE Department Lafayette College Easton, Pennsylvania ECE Computer Organization Lecture 4 - Instruction.
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.
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.
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Computer Organization and Design Instruction Sets Montek Singh Wed, Sep 12, 2012 Lecture 5.
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
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.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
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.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Computer Architecture Instruction Set Architecture
MIPS Instruction Set Advantages
COMPUTER ARCHITECTURE & OPERATIONS I
Computer Organization and Design Instruction Sets - 2
Instructions: Language of the Computer
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
ELEN 468 Advanced Logic Design
Computer Organization and Design Instruction Sets - 2
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
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
Single-Cycle CPU DataPath.
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
Lecture 5: Procedure Calls
The University of Adelaide, School of Computer Science
Part II Instruction-Set Architecture
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Computer Instructions
Instructions and Conditional Execution
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
MIPS Assembly.
Flow of Control -- Conditional branch instructions
Instruction encoding The ISA defines Format = Encoding
MIPS assembly.
CS352H Computer Systems Architecture
Reduced Instruction Set Computer (RISC)
MIPS Arithmetic and Logic Instructions
MIPS Arithmetic and Logic Instructions
MIPS instructions.
Presentation transcript:

ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Other handouts Course schedule with due dates To handout next time HW#1 Combinations to AV system, etc. 5581 (1988 in 113 IST) Call AV hot line at 8-777-0035

Computer Organization - Previously covered Byte/Word addressing Registers Program counter – 32 bits Keyboard, Mouse Computer Processor (CPU) Memory (where programs, & data live) Devices Disk (where programs, & data live when not running) Control Input Datapath Output Display, Printer

MIPS Registers Fast access to program data Register names: $0-$31 or R0-R31 Specialized names based on usage convention Register R0/$0/$zero: hardwired to constant zero $t0-$t7 ($8-$15) - “temporary” registers $s0-$s7 ($16-$23) - “saved” registers $sp - stack pointer Allow relative addressing Other special-purpose registers

MIPS Instruction Types Arithmetic & Logical - manipulate data in registers add $s1, $s2, $s3 $s1 = $s2 + $s3 or $s3, $s4, $s5 $s3 = $s4 OR $s5 Instruction usage (assembly) add dest, src1, src2 dest = src1 + src2 Instruction characteristics Always 3 operands: 2 sources + destination Operand order is fixed Operands are always general-purpose registers

MIPS Instruction Types - 2 Data Transfer - move register data to/from memory lw $s1, 100($s2) $s1 = Memory[$s2 + 100] sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Branch - alter program flow beq $s1, $s2, 25 if ($s1==$s2) skip 25 instructions

Arithmetic/Logical Instructions: Binary Representation op rs rt rd funct shamt 6 bits 5 bits Each instruction – 32 bits 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

MIPS Instructions All instructions exactly 32 bits wide Different formats for different purposes Similarities in formats ease implementation 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits R-Format op rs rt rd shamt funct 6 bits 5 bits 5 bits 16 bits I-Format (e.g., Load/Store, Branch) op rs rt offset 6 bits 26 bits J-Format (e.g., Jump) op address

MIPS Arithmetic Instructions Instruction Example Meaning Comments add add $1,$2,$3 $1 = $2 + $3 3 operands; subtract sub $1,$2,$3 $1 = $2 – $3 3 operands; add immediate addi $1,$2,100 $1 = $2 + 100 + constant; add unsigned addu $1,$2,$3 $1 = $2 + $3 3 operands; subtract unsigned subu $1,$2,$3 $1 = $2 – $3 3 operands; add imm. unsign. addiu $1,$2,100 $1 = $2 + 100 + constant; multiply mult $2,$3 Hi, Lo = $2 x $3 64-bit signed product multiply unsigned multu$2,$3 Hi, Lo = $2 x $3 64-bit unsigned product divide div $2,$3 Lo = $2 ÷ $3, Lo = quotient, Hi = remainder Hi = $2 mod $3 divide unsigned divu $2,$3 Lo = $2 ÷ $3, Unsigned quotient & remainder Move from Hi mfhi $1 $1 = Hi Used to get copy of Hi Move from Lo mflo $1 $1 = Lo Used to get copy of Lo

MIPS Logical Instructions Instruction Example Meaning Comment and and $1,$2,$3 $1 = $2 & $3 3 reg. operands; Logical AND or or $1,$2,$3 $1 = $2 | $3 3 reg. operands; Logical OR xor xor $1,$2,$3 $1 = $2 Å $3 3 operands; Logical XOR and immediate andi $1,$2,10 $1 = $2 & 10 Logical AND reg,constant or immediate ori $1,$2,10 $1 = $2 | 10 Logical OR reg, constant xor immediate xori $1, $2,10 $1 = $2 Å 10 Logical XOR reg, constant shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant

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 lw $s1, 100($s2) $s1 = Memory[$s2 + 100] sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Uses: Accessing a variable in main memory Accessing an array element 32-bit base address 16-bit offset

Example - Loading a Variable 8 Registers R0=0 (constant) R1 R2=0x10 R30 R31 R3 R4 + Memory 0x00 Variable Z = 692310 Variable X Variable Y 0x04 0x08 0x0c 0x10 0x14 0x18 0x1c R2=0x10 R5 = 692310 Variable Z = 692310 lw R5,8(R2)

Data Transfer Instructions Binary Representation op rs rt offset 6 bits 5 bits 16 bits 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 Address source for sw destination for lw

I-Format vs. R-Format Instructions Compare with R-Format rd funct shamt 6 bits 5 bits R-Format op rs rt offset 6 bits 5 bits 16 bits I-Format op rs rt Note similarity!

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 beq $s1, $s2, 25 if ($s1==$s2) PC = PC + 4 + 4*25 else PC = PC + 4 Example C Code if (i==j) goto L1; f = g + h; L1: f = f - i; Assembly beq $s3, $s4, L1 add $s0, $s1, $s2 L1: sub $s0, $s0, $s3 { Address of next sequential instruction Offset in bytes

Example: Compiling C if-then-else Example C Code if (i==j) f = g + h; else f = g - h; Assembly bne $s3, $s4, Else add $s0, $s1, $s2 j Exit; # new: unconditional jump Else: sub $s0, $s1, $s2 Exit: New Instruction: Unconditional jump j LABEL # goto Label

Binary Representation - Branch op rs rt offset 6 bits 5 bits 16 bits 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 + 4 + (offset << 2) else pc = pc + 4; Offset is specified in instruction words (why?) What is the range of the branch target addresses? Conversion to byte offset

Comparisons - What about <,  , >,  ? bne, beq provide equality comparison slt (set on less than) 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

Binary Representation - Jump op address 6 bits 26 bits Jump Instruction uses J-Format (op=2) What happens during execution? PC = PC[31:28] : (IR[25:0] << 2) Concatenate upper 4 bits of PC to form complete 32-bit address Conversion to byte offset

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 addi $29, $29,-8 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? Arithmetic instructions sign-extend immed. Logical instructions don’t sign extend immed. ori $5, $zero, 666

Larger Constants Immediate operations provide only for 16-bit constants Because 16 bits fit neatly in a 32-bit instruction Because most constants are small (i.e., < 16 bits) What about when we need larger constants? Use "load upper immediate - lui” (I-Format) lui $t0, 1010101010101010 Then use ori to fill in lower 16 bits: ori $t0, $t0, 1110111011101100 (original contents) $t0 1010101010101010 0000000000000000 filled with zeros 1110111011101100 $t0 1010101010101010 0000000000000000

MIPS Registers and Usage Name Register number Usage the constant value 0 $zero 1 reserved for assembler $at 2-3 values for results and expression evaluation $v0-$v1 4-7 arguments $a0-$a3 8-15 temporary registers $t0-$t7 16-23 saved registers $s0-$s7 24-25 more temporary registers $t8-$t9 26-27 reserved for Operating System kernel $k0-$k1 28 global pointer $gp 29 stack pointer $sp 30 frame pointer $fp 31 return address $ra