COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Similar documents
Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter 2A Instructions: Language of the Computer

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

Unsigned Binary Integers

Unsigned Binary Integers

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Computer Architecture

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Chapter 2. Instructions:

CS3350B Computer Architecture MIPS Instruction Representation

MIPS Instruction Set Architecture (2)

COMPUTER ORGANIZATION AND DESIGN

Chapter 3. Instructions:

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Chapter 2. Instructions: Language of the Computer

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Chapter 2: Instructions:

ECE232: Hardware Organization and Design

MIPS%Assembly% E155%

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

Chapter 2. Instruction Set Architecture (ISA)

CS222: MIPS Instruction Set

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

Topic Notes: MIPS Instruction Set Architecture

Thomas Polzer Institut für Technische Informatik

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Lecture 4: MIPS Instruction Set

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Lecture 5: Procedure Calls

Instructions: Language of the Computer

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI.

Computer Architecture

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

EEC 581 Computer Architecture Lecture 1 Review MIPS

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Instructions: Language of the Computer

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

ECE 154A Introduction to. Fall 2012

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

CENG3420 L03: Instruction Set Architecture

Computer Architecture. Lecture 2 : Instructions

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

CENG3420 Lecture 03 Review

Computer Organization MIPS ISA

Levels of Programming. Registers

Architecture II. Computer Systems Laboratory Sungkyunkwan University

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

All instructions have 3 operands Operand order is fixed (destination first)

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

Machine Instructions - II. Hwansoo Han

ECE369. Chapter 2 ECE369

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

Chapter 2. Baback Izadi Division of Engineering Programs

ECE260: Fundamentals of Computer Engineering

Course Administration

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

ECE260: Fundamentals of Computer Engineering

Instructions: Language of the Computer

Chapter 2. Instruction Set. The MIPS Instruction Set. Arithmetic Operations. Instructions: Language of the Computer

Computer Architecture Computer Science & Engineering. Chapter 2. Instructions: Language of the Computer BK TP.HCM

CS/COE1541: Introduction to Computer Architecture

Instruction Set Design and Architecture

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Reduced Instruction Set Computer (RISC)

LECTURE 2: INSTRUCTIONS

Chapter 2. Instructions: Language of the Computer

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

The MIPS Instruction Set Architecture

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Reduced Instruction Set Computer (RISC)

MIPS Coding Continued

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

CS3350B Computer Architecture MIPS Introduction

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CSCI 402: Computer Architectures

Computer Architecture. MIPS Instruction Set Architecture

CS 61c: Great Ideas in Computer Architecture

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Computer Architecture. The Language of the Machine

Transcription:

COMPSCI 313 S2 2018 Computer Organization 7 MIPS Instruction Set

Agenda & Reading MIPS instruction set MIPS I-format instructions MIPS R-format instructions 2

7.1 MIPS Instruction Set MIPS Instruction Set Language of the Machine More primitive than higher level languages No sophisticated control flow Very restrictive MIPS Arithmetic Instructions We ll be working with the MIPS instruction set architecture Similar to other architectures developed since the 1980's Used by NEC, Nintendo, Silicon Graphics, Sony Design goals Maximize performance and minimize cost, reduce design time 3

7.1 MIPS Instruction Set MIPS Instruction Set Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register numbers, Regularity! 4

7.1 MIPS Instruction Set MIPS Instruction Set Instruction complexity is only one variable Lower instruction count vs. higher CPI / lower clock rate Design Principles: Simplicity favors regularity Smaller is faster Good design demands compromise Make the common case fast Instruction set architecture A very important abstraction indeed! 5

7.1 MIPS Instruction Set MIPS Registers Registers more versatile: MIPS arithmetic instructions can read 2, operate on them, and write 1 per instruction MIPS data transfer only read or write 1 operand per instruction, and no operation Fast location data Data must be in registers to perform arithmetic instruction 32 general-purpose registers Program counter (PC, 32-bits) stores the current instruction address 6

7.1 MIPS Instruction Set MIPS Registers (for compilation) $at(1), $k0(26) and $k1(27) are reserved for the assembler and operating system and should not be used by user program $a0-$a3(4-7) are used to pass the first four arguments to routines (remaining arguments are passed on the stack) $v0-$v1(2,3) are used to return values from function $t0-t9 (8-15, 24, 25) are caller-saved registers that hold temporary quantities that need not be preserved across calls $s0-s7 (16-23) are callee-saved registers that hold long-lived values that should be preserved across calls $gp (28) is the global pointer that points to the middle of a 64K memory in the static data segment $sp (29) is the stack pointer that points to the first free location of the stack $ra (31) is used to store the return address from a procedure call $fp (30) is the frame pointer 7

7.1 MIPS Instruction Set MIPS Registers (for compilation) Register name Number Usage $zero 0 Constant 0 $at 1 Reserved for assembler $v0, $v1 2, 3 Result of a function $a0-$a3 4-7 Function arguments $t0-$t9 8-15, 24, 25 Temporary $s0-$s7 16-23 Saved temporary $k0, $k1 26,27 Reserved of OS $gp 28 Pointer to global area $sp 29 Stack pointer $fp 30 Frame pointer $ra 31 Return address of function 8

7.2 MIPS R-format Instructions MIPS R-format Instruction fields op: operation code (opcode) rs: first source register number rt: second source register number rd: destination register number shamt: shift amount (00000 for now) funct: function code (extends opcode) op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 9

7.2 MIPS R-format Instructions R-format Example add $t0, $s1, $s2 special $s1 $s2 $t0 0 add 0 17 18 8 0 32 000000 10001 10010 01000 00000 100000 00000010001100100100000000100000 2 = 02324020 16 op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 10

Base 16 7.2 MIPS R-format Instructions MIPS R-format Compact representation of bit strings 4 bits per hex digit 0 0000 4 0100 8 1000 c 1100 1 0001 5 0101 9 1001 d 1101 2 0010 6 0110 a 1010 e 1110 3 0011 7 0111 b 1011 f 1111 Example: eca8 6420 1110 1100 1010 1000 0110 0100 0010 0000 11

7.3 MIPS I-format Instructions MIPS I-format Immediate arithmetic and load/store instructions rt: destination or source register number Constant: 2 15 to +2 15 1 Address: offset added to base address in rs Design Principle 4: Good design demands good compromises Different formats complicate decoding, but allow 32-bit instructions uniformly Keep formats as similar as possible op rs rt constant or address 6 bits 5 bits 5 bits 16 bits 12

7.3 MIPS I-format Instructions MIPS I-format addi $s3, $s2, 0x5f addi $s2 $s3 5f 16 8 18 19 5f 16 001000 10010 10011 0000 0000 0101 1111 0010 0010 0101 0011 0000 0000 0101 1111 2 = 2253005f 16 op rs rt constant or address 6 bits 5 bits 5 bits 16 bits 13

7.3 MIPS I-format Instructions MIPS Instruction Examples add $s2, $s1, $s0 0x02309020 addi $s2, $s1, 0x6f 0x2232006F sub $s3, $s2, $s4 0x02549822 andi $s1, $s0, 0x4c 0x3211004C 14

7.3 MIPS I-format Instructions Stored Program Computers Instructions represented in binary, just like data Instructions and data stored in memory Programs can operate on programs e.g., compilers, linkers, Binary compatibility allows compiled programs to work on different computers Standardized ISAs The BIG Picture 15

7.4 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 16

7.4 Logical Operations Shift Operations shamt: how many positions to shift Shift left logical Shift left and fill with 0 bits sll by i bits multiplies by 2 i Shift right logical Shift right and fill with 0 bits srl by i bits divides by 2 i (unsigned only) op rs rt rd shamt funct 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits 17

7.4 Logical Operations Exercise 7.1 Q1.1. Assume the following register contents: $t0 = 0xAAAAAAAA For the register values shown above, what is the value of $t2 for the following sequence of instructions? sll $t2, $t0, 4 18

7.4 Logical Operations AND Operations Useful to mask bits in a word Select some bits, clear others to 0 and $t0, $t1, $t2 $t2 $t1 $t0 0000 0000 0000 0000 0000 1101 1100 0000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0000 0000 0000 1100 0000 0000 19

7.4 Logical Operations OR Operations Useful to include bits in a word Set some bits to 1, leave others unchanged or $t0, $t1, $t2 $t2 $t1 $t0 0000 0000 0000 0000 0000 1101 1100 0000 0000 0000 0000 0000 0011 1100 0000 0000 0000 0000 0000 0000 0011 1101 1100 0000 20

7.4 Logical Operations 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 $t0 0000 0000 0000 0000 0011 1100 0000 0000 1111 1111 1111 1111 1100 0011 1111 1111 21

7.4 Logical Operations Exercise 7.2 Q2.1. Provide the type, assembly language instruction, and binary representation of instruction described by the following MIPS fields: op=0, rs=3, rt=2, rd=3, shamt=0, funct=34 Q2.2. Provide the type, assembly language instruction, and binary representation of instruction described by the following MIPS fields: op=0x23, rs=1, rt=2, const=0x4 22

Conditional Operations Branch to a labeled instruction if a condition is true Otherwise, continue sequentially beq rs, rt, L1 if (rs == rt) branch to instruction labeled L1; bne rs, rt, L1 if (rs!= rt) branch to instruction labeled L1; j L1 7.5 Instructions for Making Decisions unconditional jump to instruction labeled L1 23

Compiling If Statements C code: 7.5 Instructions for Making Decisions f, g, in $s0, $s1, if (i==j) f = g+h; else f = g-h; Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit: 24

Compiling Loop Statements C code: 7.5 Instructions for Making Decisions while (save[i] == k) i += 1; i in $s3, k in $s5, address of save in $s6 Compiled MIPS code: Loop: sll $t1, $s3, 2 add $t1, $t1, $s6 lw $t0, 0($t1) bne $t0, $s5, Exit addi $s3, $s3, 1 j Loop Exit: 25

7.5 Instructions for Making Decisions Basic Blocks A basic block is a sequence of instructions with No embedded branches (except at end) No branch targets (except at beginning) A compiler identifies basic blocks for optimization An advanced processor can accelerate execution of basic blocks 26

7.5 Instructions for Making Decisions More Conditional Operations Set result to 1 if a condition is true Otherwise, set to 0 slt rd, rs, rt if (rs < rt) rd = 1; else rd = 0; slti rt, rs, constant if (rs < constant) rt = 1; else rt = 0; Use in combination with beq, bne slt $t0, $s1, $s2 # if ($s1 < $s2) bne $t0, $zero, L # branch to L 27

7.5 Instructions for Making Decisions Branch Instruction Design Why not blt, bge, etc? Hardware for <,, slower than =, Combining with branch involves more work per instruction, requiring a slower clock All instructions penalized! beq and bne are the common case This is a good design compromise 28

7.5 Instructions for Making Decisions Signed vs. Unsigned Signed comparison: slt, slti Unsigned comparison: sltu, sltui Example $s0 = 1111 1111 1111 1111 1111 1111 1111 1111 $s1 = 0000 0000 0000 0000 0000 0000 0000 0001 slt $t0, $s0, $s1 # signed 1 < +1 $t0 = 1 sltu $t0, $s0, $s1 # unsigned +4,294,967,295 > +1 $t0 = 0 29

Summary On completion of this module, you are able to Familiar with the MIPS instruction set Write simple programs with MIPS instructions References: Textbook - Computer Organization and Design - The Hardware Software Interface Chapter 2 30

Q & A (break) 5-10 minutes break 31