CS 4200/5200 Computer Architecture I

Similar documents
ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

Computer Architecture. The Language of the Machine

The MIPS Instruction Set Architecture

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

CS222: MIPS Instruction Set

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Chapter 2: Instructions:

F. Appendix 6 MIPS Instruction Reference

MIPS Instruction Reference

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Computer Architecture. MIPS Instruction Set Architecture

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

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

CS3350B Computer Architecture MIPS Instruction Representation

MIPS Instruction Format

Computer Architecture

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

CSSE 232 Computer Architecture I. I/O and Addressing

M2 Instruction Set Architecture

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

EE108B Lecture 3. MIPS Assembly Language II

MIPS Instruction Set

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

A Processor! Hakim Weatherspoon CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

Course Administration

MIPS Reference Guide

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Chapter 2A Instructions: Language of the Computer

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

CS3350B Computer Architecture

CMPE324 Computer Architecture Lecture 2

Midterm. Sticker winners: if you got >= 50 / 67

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

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

Computer Architecture

Topic Notes: MIPS Instruction Set Architecture

CS/COE1541: Introduction to Computer Architecture

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

Instructions: Language of the Computer

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

CS61CL Machine Structures. Lec 5 Instruction Set Architecture

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

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

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

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

Unsigned Binary Integers

Unsigned Binary Integers

Midterm Questions Overview

Review of the Machine Cycle

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

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

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

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

Midterm Questions Overview

MIPS%Assembly% E155%

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

CENG3420 Lecture 03 Review

CS3350B Computer Architecture MIPS Introduction

MIPS Assembly Language. Today s Lecture

SPIM Instruction Set

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

Mips Code Examples Peter Rounce

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

COMPUTER ORGANIZATION AND DESIGN

software hardware Which is easier to change/design???

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

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

TSK3000A - Generic Instructions

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

Computer Organization MIPS ISA

MACHINE LANGUAGE. To work with the machine, we need a translator.

Computer Organization & Design

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

ECE232: Hardware Organization and Design

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

Levels of Programming. Registers

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

INSTRUCTION SET COMPARISONS

Lecture 4: MIPS Instruction Set

MIPS Memory Access Instructions

Instruction Set Architectures Part I: From C to MIPS. Readings:

Chapter 2. Instructions:

MIPS Assembly Programming

CS 61c: Great Ideas in Computer Architecture

ECE 15B Computer Organization Spring 2011

ECE 154A Introduction to. Fall 2012

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

MIPS (SPIM) Assembler Syntax

Examples of branch instructions

Chapter 2. Instructions: Language of the Computer

Instruction Set Architecture (ISA)

Transcription:

CS 4200/5200 Computer Architecture I MIPS Instruction Set Architecture Dr. Xiaobo Zhou Department of Computer Science CS420/520 Lec3.1 UC. Colorado Springs Adapted from UCB97 & UCB03 Review: Organizational Trade-offs CPU time = Seconds = Instructions x Cycles x Seconds Program Program Instruction Cycle Application Programming Language Compiler ISA Datapath Control Function Units Transistors Wires Pins Instruction Mix CPI Cycle Time CS420/520 Lec3.2 UC. Colorado Springs Adapted from UCB97 & UCB03

= Review: Amdahl's Law ExTime after improvement = ExTime unaffected + Extime affected / amount of improvement Speedup due to enhancement E: ExTime w/o E Performance w/ E Speedup(E) = -------------------- = --------------------------- ExTime w/ E Performance w/o E Suppose that enhancement E accelerates a fraction F of the task by a factor S, and the remainder of the task is unaffected then, ExTime(with E) = ((1-F) + F/S) X ExTime(without E) Speedup(with E) = ExTime(without E) 1 ((1-F) + F/S) X ExTime(without E) 1 v (1-F) + F/S CS420/520 Lec3.3 UC. Colorado Springs Adapted from UCB97 & UCB03 Instruction Set Design software instruction set hardware An instruction is a binary code, which specifies a basic operation (e.g. add, subtract, and, or) for the computer Operation Code: defines the operation type Operands: operation source and destination CS420/520 Lec3.4 UC. Colorado Springs Adapted from UCB97 & UCB03

Levels of Representation High Level Language Program Compiler Assembly Language Program Assembler Machine Language Program temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) 1000 1100 0100 1111 0000 0000 0000 0000 1000 1111 0101 1000 0000 1001 1100 0110 1010 1110 1010 1111 0101 1000 0000 1001 1010 1100 0000 1001 1100 0110 1010 1111 Machine Interpretation Control Signal Specification CS420/520 Lec3.5 UC. Colorado Springs Adapted from UCB97 & UCB03 MIPS R2000 / R3000 Registers MIPS (NEC, SGI, Sony, Nintendo), a typical of instructions after 1980s. 32-bit machine --> Programmable storage 2^32 x 4 bytes 31 x 32-bit GPRs (R0 = 0) r0 0 r1 32 x 32-bit FP regs HI, LO, PC Big Endian r31 PC Addressing modes: lo hi register immediate displacement PC-relative pseudo-direct All instructions are 32-bit wide and must be aligned -- words must start at address that are multiple of 4. CS420/520 Lec3.6 UC. Colorado Springs Adapted from UCB97 & UCB03

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 sub immediate subi $1,$2,100 $1 = $2-100 - constant CS420/520 Lec3.7 UC. Colorado Springs Adapted from UCB97 & UCB03 Example E.g. f= (g+h) - (i+j), assuming f, g, h, i, j be assigned to $1, $2, $3, $4, $5 add $7, $2, $3 add $8, $4, $5 sub $1, $7, $8 // register $7 contains g+h // register $8 contains i+j // register $1 (f) gets the result CS420/520 Lec3.8 UC. Colorado Springs Adapted from UCB97 & UCB03

MIPS logic instructions Instruction Example Meaning Comment and and $1,$2,$3 $1 = $2 & $3 Logical AND or or $1,$2,$3 $1 = $2 $3 Logical OR xor xor $1,$2,$3 $1 = $2 $3 Logical XOR nor nor $1,$2,$3 $1 = ~($2 $3) Logical NOR and imme. andi $1,$2, 100 $1 = $2 & 100 AND constant x y x and y x or y x xor y x nor y 0 0 0 0 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 0 CS420/520 Lec3.9 UC. Colorado Springs Adapted from UCB97 & UCB03 MIPS data transfer instructions Instruction LW $1, 30($2) LH $1, 40($3) LB $1, 40($3) SW $3, 500($4) SH $3, 502($2) SB $2, 41($3) Comment Load word Load half a word Load byte Store word Store half Store byte In MIPS64: LD (load double word) LD $1, 30($2) load a double-word SD $3, 500($4) store a double-word CS420/520 Lec3.10 UC. Colorado Springs Adapted from UCB97 & UCB03

Example Assume A is an array of 100 words, and compiler has associated the variables g and h with the register $1 and $2. Assume the base address of the array is in $3. Translate g=h+a[8] lw $4, 8($3); add $1, $2, $4; // $4 <-- A[8] lw $4, 32($3); // $4 <-- A[8] add $1, $2, $4 A[12] = h+a[8] SW $1, 48($3) CS420/520 Lec3.11 UC. Colorado Springs Adapted from UCB97 & UCB03 Example Assume A is an array of 100 words, and compiler has associated the variables g, h, and i with the register $1, $2, $5. Assume the base address of the array is in $3. Translate g=h+a[i] add $6, $5, $5; add $6, $6, $6; add $4, $3, $6; lw $7, 0 ($4); add $1, $2, $7; // $6 = 2i // $6 = 4i // $4 <---absolute mem. address of // A[i], used as new base // $7 = A[i] // g = h + A[i] CS420/520 Lec3.12 UC. Colorado Springs Adapted from UCB97 & UCB03

MIPS branch, jump, compare instructions Instruction Example Meaning branch on equal beq $1,$2,100 if ($1 == $2) go to PC+4+100 Equal test; PC relative branch branch on not eq. bne $1,$2,100 if ($1!= $2) go to PC+4+100 Not equal test; PC relative branch on eq. to 0 beqz $1,100 if ($1==0) go to PC+4+100 Zero test; PC relative (pseudo-instruction; using $0) beq, bne, blt, blez, bgt, bgez jump j 10000 go to 10000 Jump to target address jump register jr $31 go to $31 For switch, procedure return jump and link jal 10000 $31 = PC + 4; go to 10000 For procedure call set on less than slt $1,$2,$3 if ($2 < $3) $1=1; else $1=0 Compare less than; 2 s comp. set less than imm. slti $1,$2,100 if ($2 < 100) $1=1; else $1=0 Compare < constant; 2 s comp. CS420/520 Lec3.13 UC. Colorado Springs Adapted from UCB97 & UCB03 Example if (i==j) go to L1; f = g+ h; L1: f = f - i; Assuming f, g, h, i, j ~ $1, $2, $3, $4, $5 beq $4, $5, L1 add $1, $2, $3 L1: sub $1, $1, $4 i == j? no f = g+h yes L1: f = f - i CS420/520 Lec3.14 UC. Colorado Springs Adapted from UCB97 & UCB03

Example Loop: g = g +A[i]; i = i+ j; if (i!= h) go to Loop: Assuming variables g, h, i, j ~ $1, $2, $3, $4 and base address of array is in $5 Loop: add $7, $3, $3 add $7, $7, $7 add $7, $7, $5 lw $6, 0($7) add $1, $1, $6 // g= g+a[i] add $3, $3, $4 bne $3, $2, Loop; g = g +A[i] i=i+j i i!= h? no yes CS420/520 Lec3.15 UC. Colorado Springs Adapted from UCB97 & UCB03 Example while (A[i]==k) i = i+j; Assume i, j, and k ~ $17, $18, $19 and base of A is in $3 A[i] == k? Yes i = i + j no Exit CS420/520 Lec3.16 UC. Colorado Springs Adapted from UCB97 & UCB03

Example while (A[i]==k) i = i+j; Assume i, j, and k ~ $17, $18, $19 and base of A is in $3 Loop: add $20, $17, $17 add $20, $20, $20 add $20, $20, $3 Exit: lw $21,0($20) bne $21, $19, Exit //exit loop if A[I]! =k add $17, $17, $18 j Loop CS420/520 Lec3.17 UC. Colorado Springs Adapted from UCB97 & UCB03 MIPS Fields R-format: Register (direct) 6 5 5 5 5 6 op rs rt rd shamt funct op: basic operation of the instruction, called opcode rs, the first register source operand rt: the second register source operand rd: the register destination operand shamt: shift amount funct: function, select the variant of the op field. I-format: Immediate 6 5 5 16 op rs rt immediate J-format: 6 26 jump op addr. CS420/520 Lec3.18 UC. Colorado Springs Adapted from UCB97 & UCB03

MIPS Addressing Modes/Instruction Formats R-format: Register (direct) I-format: Immediate Base+offset displacement 6 5 5 5 5 6 op rs rt rd sht fun register op rs rt immed 6 5 5 16 op rs rt immed Memory register + PC-relative op rs rt immed Memory J-format: pseudodirect PC + 6 26 op addr. Memory CS420/520 Lec3.19 UC. Colorado Springs Adapted from UCB97 & UCB03 Example while (A[i]==k) i = i+j; Assume i, j, and k ~ $17, $18, $19 and base of A is in $3 Loop: add $20, $17, $17 add $20, $20, $20 add $20, $20, $3 lw $21,0($20) bne $21, $19, Exit add $17, $17, $18 j Loop Exit: Assume the loop is placed starting at loc 8000 8000: 0 17 17 20 0 32 0 20 20 20 0 32 0 20 3 20 0 32 35 20 21 0 5 21 19 8 -> 2 0 17 18 17 0 32 2 8000 -> 2000 CS420/520 Lec3.20 UC. Colorado Springs Adapted from UCB97 & UCB03

MIPS arithmetic & logical 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; and and $1,$2,$3 $1 = $2 & $3 3 reg. operands; or or $1,$2,$3 $1 = $2 $3 3 reg. operands; xor xor $1,$2,$3 $1 = $2 $3 3 reg. operands; nor nor $1,$2,$3 $1 = ~($2 $3) 3 reg. operands; 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 CS420/520 Lec3.21 UC. Colorado Springs Adapted from UCB97 & UCB03 MIPS data transfer instructions Instruction LW $1, 30($2) LH $1, 40($3) LB $1, 40($3) Comment Load word Load half a word Load byte SW $3, 500($4) SH $3, 502($2) SB $2, 41($3) Store word Store half Store byte In MIPS64: LD (load double word) LD $1, 30($2) load a double-word SD $3, 500($4) store a double-word CS420/520 Lec3.22 UC. Colorado Springs Adapted from UCB97 & UCB03

Compare and Branch Compare and Branch BEQ rs, rt, offset if R[rs] == R[rt] then PC-relative branch BNE rs, rt, offset <> Compare to zero and branch BLEZ rs, offset if R[rs] <= 0 then PC-relative branch BGTZ rs, offset > BLT < BGEZ >= BLTZAL rs, offset if R[rs] < 0 then branch and link (into R 31) BGEZAL >= CS420/520 Lec3.23 UC. Colorado Springs Adapted from UCB97 & UCB03 Reading and Preview Reading: CO 4: Chapter 2 (MIPS) CA 5: Appendix A (ISA) CS420/520 Lec3.24 UC. Colorado Springs Adapted from UCB97 & UCB03