MIPS Instruction Set Architecture (1)

Similar documents
Architecture I. Computer Systems Laboratory Sungkyunkwan University

Chapter 2A Instructions: Language of the Computer

CS3350B Computer Architecture

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

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

CS3350B Computer Architecture MIPS Introduction

Instructions: Language of the Computer

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

ECE232: Hardware Organization and Design

Instructions: Language of the Computer

Chapter 2: Instructions:

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

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

Chapter 1. Computer Abstractions and Technology

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

ECE 154A Introduction to. Fall 2012

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

ECE232: Hardware Organization and Design

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

Machine-level Representation of Programs

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

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

Computer Organization MIPS ISA

CSEE 3827: Fundamentals of Computer Systems

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

Course Administration

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

CS3350B Computer Architecture MIPS Instruction Representation

ECE331: Hardware Organization and Design

COMPUTER ORGANIZATION AND DESIGN

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

CENG3420 Lecture 03 Review

MIPS Memory Access Instructions

Computer Architecture

Review of instruction set architectures

Chapter 2. Instructions: Language of the Computer

Computer Architecture. MIPS Instruction Set Architecture

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

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

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

CS222: MIPS Instruction Set

Machine-level Representation of Programs

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

EC 413 Computer Organization

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

Unsigned Binary Integers

Unsigned Binary Integers

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

Chapter 2. Baback Izadi Division of Engineering Programs

CENG3420 L03: Instruction Set Architecture

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

ECE260: Fundamentals of Computer Engineering

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

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

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

LECTURE 2: INSTRUCTIONS

Instructions: Language of the Computer

Computer Architecture

EEC 581 Computer Architecture Lecture 1 Review MIPS

Lecture 4: Instruction Set Architecture

Chapter 2. Instructions: Language of the Computer. Jiang Jiang

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

Reduced Instruction Set Computer (RISC)

The Processor (1) Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Instruction Set Architecture. "Speaking with the computer"

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

MIPS Instruction Set Architecture (2)

Reduced Instruction Set Computer (RISC)

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

Control Instructions

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

Chapter 3. Instructions:

Chapter 2. Instructions: Language of the Computer

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

Computer Architecture. Lecture 2 : Instructions

Chapter 2. Instruction Set Architecture (ISA)

Communicating with People (2.8)

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

Levels of Programming. Registers

Computer Organization and Components

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

Chapter 2. Instructions:

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

ECE369. Chapter 2 ECE369

Processor Architecture

Chapter 2 Instruction: Language of the Computer

Chapter 2. Instructions: Language of the Computer

Computer Systems Laboratory Sungkyunkwan University

MIPS%Assembly% E155%

Instruction Set Architecture (ISA)

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

CS/COE1541: Introduction to Computer Architecture

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

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

2.7 Supporting Procedures in hardware. Why procedures or functions? Procedure calls

Transcription:

MIPS Instruction Set Architecture (1) Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Overview Textbook: P&H 2.1-2.4 (both 4 th Ed. and 5 th Ed.) Architecture Operations of Computer Hardware Operands of Computer Hardware Signed and Unsigned Operands EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 2

Architecture* * Adapted from the 2012 course slides offered by Prof. Jinsoo Kim (SKKU) EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Architecture the attributes of a system as seen by the programmer, i.e., the conceptual structure and functional behavior, as distinct from the organization of the data flow and controls, the logical design, and the physical implementation -- Amdahl, Blaauw, and Brooks, Architecture of the IBM System/360, IBM Journal of Research and Development, April 1964. The visible interface between software and hardware What the user (OS, compiler,...) needs to know to reason about how the machine behaves Abstracted from the details of how it may accomplish its task EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 4

Architecture Computer Architecture defines Instruction set architecture (ISA) Instruction set Operand types Data types (integers, FPs,...) Memory addressing modes,... Registers and other state The interrupt/exception model Memory management and protection Virtual and physical address layout I/O model... EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 5

Architecture Microarchitecture Organization of the machine below the visible level Number/location of functional units Pipeline/cache configurations Programmer transparent techniques: prefetching,... Must provide same meaning (semantics) as the visible architecture model Implementation Hardware realization Logic circuits, VLSI technology, process,... EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 6

Architecture vs. Microarchitecture: ARM Family (Microarchitecture) Architecture Architecture features * Source: arm.com EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 7

What is ISA? XScale (IXA) Itanium (IA-64) Architecture vs. Microarchitecture: IA-32 Intel 64 Intel s IA-32 Architecture Brand Name (IA-32e, EM64T, x86-64) Microarchitecture Brand Name P5 P6 NetBurst Mobile Core Processor Brand Name Pentium Pentium MMX Pentium Pro Pentium II Pentium III Pentium 4 Pentium D Pentium M Core Duo/Solo Core 2 Quad/Duo/Solo Processor Code Name P5, P54C, P54CS P55C, Tillamook Pentium Pro Klamath, Deschutes Katmai, Coppermine, Tualatin Willamette, Northwood, Prescott, Cedar Mill Smithfield, Presler Banias, Dothan Yonah Conroe, Allendale, Wolfdale Merom, Penryn Kentsfield, Yorkfield EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 8

Operations of Computer Hardware EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common 1 4 0 0 O th e r 1 3 0 0 S PA R C Early computers had very 1 2 0 0 H ita c h i S H simple instruction sets 11 0 0 P o w e r P C M o to ro la 6 8 K 1 0 0 0 Simplified implementation M IP S 9 0 0 IA -3 2 Many modern computers also 8 0 0 A R M 7 0 0 have simple instruction sets 6 0 0 So-called RISC 5 0 0 (Reduced Instruction Set Computer) 4 0 0 e.g., MIPS, ARM, PowerPC, etc. 3 0 0 2 0 0 1 0 0 0 1 9 9 8 1 9 9 9 2 0 0 0 2 0 0 1 2 0 0 2 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 10

The MIPS Instruction Set Used as the example throughout the book Stanford MIPS commercialized by MIPS Technologies (www.mips.com) Large share of embedded core market Applications in consumer electronics, network/storage equipment, cameras, printers, Almost 100 million MIPS processors manufactured in 2002 Used by NEC, Nintendo, Cisco, Silicon Graphics, Sony,... Typical of many modern ISAs See MIPS Reference Data tear-out card ( green card ), and Appendixes B and E EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 11

Arithmetic Operations Add and subtract, three operands Two sources and one destination add a, b, c # a gets b + c All arithmetic operations have this form Design Principle 1: Simplicity favors regularity Regularity makes implementation simpler Simplicity enables higher performance at lower cost EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 12

Arithmetic Example C code: f = (g + h) - (i + j); Compiled MIPS code (assembly): add t0, g, h # temp t0 = g + h add t1, i, j # temp t1 = i + j sub f, t0, t1 # f = t0 - t1 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 13

Operands of Computer Hardware EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Register Operands Arithmetic instructions use register operands MIPS has a 32 32-bit register file Use for frequently accessed data Numbered 0 to 31 32-bit data called a word Assembler names $t0, $t1,, $t9 for temporary values $s0, $s1,, $s7 for saved variables Design Principle 2: Smaller is faster c.f. main memory: millions of locations EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 15

Register Operand Example C code: f = (g + h) - (i + j); Assume f, g, h, i, j are stored in $s0, $s1, $s2, $s3, $s4 Compiled MIPS code: add $t0, $s1, $s2 add $t1, $s3, $s4 sub $s0, $t0, $t1 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 16

Register Operands: MIPS Registers 32 general-purpose registers # Name Usage 0 $zero The constant value 0 1 $at Assembler temporary 2 $v0 Values for results and 3 $v1 expression evaluation 4 $a0 Arguments 5 $a1 6 $a2 7 $a3 8 $t0 Temporaries 9 $t1 (Caller-save registers) 10 $t2 11 $t3 12 $t4 13 $t5 14 $t6 15 $t7 # Name Usage 16 $s0 Saved temporaries 17 $s1 (Callee-save registers) 18 $s2 19 $s3 20 $s4 21 $s5 22 $s6 23 $s7 24 $t8 More temporaries 25 $t9 (Caller-save registers) 26 $k0 Reserved for OS kernel 27 $k1 28 $gp Global pointer 29 $sp Stack pointer 30 $fp Frame pointer 31 $ra Return address EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 17

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 Byte Addr c.f. Little Endian: least-significant byte at least address 0 4 8 12... 32 bits of data 32 bits of data 32 bits of data 32 bits of data Word Addr 0 1 2 3 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 18

Byte Addresses Since 8-bit bytes are so useful, most architectures address individual bytes in memory Alignment restriction - the memory address of a word must be on natural word boundaries (a multiple of 4 in MIPS-32) 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) msb little endian byte 0 3 2 1 0 lsb 0 1 2 3 big endian byte 0 [Source: M. J. Irwin @ PSU] EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 19

Memory Operand Example 1 C code: g = h + A[8]; g in $s1, h in $s2, base address of A in $s3 Compiled MIPS code: 4 bytes per word Index 8 requires offset of 32 lw $t0, 32($s3) # load word add $s1, $s2, $t0 offset base register EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 20

Memory Operand Example 2 C code: A[12] = h + A[4]; h in $s2, base address of A in $s3 Compiled MIPS code: Index 4 requires offset of 16 (Again, 4 bytes per word) lw $t0, 16($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 21

Registers vs. Memory Registers are faster to access than memory Operating on memory data requires loads and stores More instructions to be executed Compiler must use registers for variables as much as possible Only spill to memory for less frequently used variables Register optimization is important! EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 22

Immediate Operands Constant data specified in an instruction addi $s3, $s3, 4 No subtract immediate instruction Just use a negative constant addi $s2, $s1, -1 Design Principle 3: Make the common case fast Small constants are common Immediate operand avoids a load instruction EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 23

The Constant Zero MIPS register 0 ($zero) is the constant 0 Cannot be overwritten (i.e., read-only) Useful for common operations E.g., move between registers add $t2, $s1, $zero EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 24

Signed and Unsigned Operands (Review) EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu)

Unsigned Binary Integers Given an n-bit number x = x + n-1 n-2 1 0 n- 12 + xn-22 +! + x12 x02 Range: 0 to +2 n 1 Example 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0 2 2 +1 2 1 +1 2 0 = 0 + + 8 + 0 + 2 + 1 = 11 10 Using 32 bits 0 to +4,294,967,295 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 26

2 s-complement Signed Integers Given an n-bit number x = -x + n-1 n-2 1 0 n- 12 + xn-22 +! + x12 x02 Range: 2 n-1 to +2 n 1 1 Example 1111 1111 1111 1111 1111 1111 1111 1100 2 = 1 2 31 + 1 2 30 + + 1 2 2 +0 2 1 +0 2 0 = 2,147,483,648 + 2,147,483,644 = 4 10 Using 32 bits 2,147,483,648 to +2,147,483,647 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 27

2 s-complement Signed Integers Bit 31 is sign bit 1 for negative numbers 0 for non-negative numbers ( 2 n 1 ) can t be represented Non-negative numbers have the same unsigned and 2scomplement representation Some specific numbers 0: 0000 0000 0000 1: 1111 1111 1111 Most-negative: 1000 0000 0000 Most-positive: 0111 1111 1111 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 28

Signed Negation Complement and add 1 Complement means 1 0, 0 1 x + x = 1111...1112 = -1 x + 1= -x Example: negate +2 +2 = 0000 0000 0010 2 2 = 1111 1111 1101 2 + 1 = 1111 1111 1110 2 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 29

Sign Extension Representing a number using more bits Preserve the numeric value In MIPS instruction set addi: extend immediate value lb, lh: extend loaded byte/halfword beq, bne: extend the displacement Replicate the sign bit to the left c.f. unsigned values: extend with 0s Examples: 8-bit to 16-bit +2: 0000 0010 => 0000 0000 0000 0010 2: 1111 1110 => 1111 1111 1111 1110 EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 30

MIPS-32 ISA Instruction Categories Computational Load/Store Jump and Branch Floating Point coprocessor Memory Management Special 3 Instruction Formats: all 32 bits wide Registers R0 - R31 PC HI LO op rs rt rd sa funct R format op rs rt immediate I format op jump target J format We will learn a variety of instructions defined by MIPS ISA next time! EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (jinkyu@skku.edu) 31