Computer Architecture

Similar documents
CS3350B Computer Architecture MIPS Instruction Representation

Chapter 2A Instructions: Language of the Computer

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

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

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

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

Computer Organization MIPS ISA

Course Administration

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

CS3350B Computer Architecture

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

Instructions: Language of the Computer

Unsigned Binary Integers

Unsigned Binary Integers

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

Chapter 2. Instructions: Language of the Computer

Instructions: Language of the Computer

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

COMPUTER ORGANIZATION AND DESIGN

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

MIPS Memory Access Instructions

CENG3420 Lecture 03 Review

CS3350B Computer Architecture MIPS Introduction

MIPS Instruction Set Architecture (2)

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

Thomas Polzer Institut für Technische Informatik

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

Reduced Instruction Set Computer (RISC)

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

Reduced Instruction Set Computer (RISC)

CENG3420 L03: Instruction Set Architecture

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

Control Instructions

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

ECE 154A Introduction to. Fall 2012

Architecture II. Computer Systems Laboratory Sungkyunkwan University

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Chapter 2. Baback Izadi Division of Engineering Programs

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

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

Computer Architecture. The Language of the Machine

Computer Architecture. MIPS Instruction Set Architecture

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

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

Machine Instructions - II. Hwansoo Han

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

ECE232: Hardware Organization and Design

Computer Architecture. Lecture 2 : Instructions

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

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

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

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

Lecture 4: MIPS Instruction Set

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

The MIPS Instruction Set Architecture

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

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

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

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

LECTURE 2: INSTRUCTIONS

EE108B Lecture 3. MIPS Assembly Language II

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

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

Instruction Set Principles. (Appendix B)

Chapter 2: Instructions:

CSCI 402: Computer Architectures

CS222: MIPS Instruction Set

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

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

MIPS (SPIM) Assembler Syntax

Instruction Set Architecture. "Speaking with the computer"

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

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

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

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

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

Chapter 2. Instructions: Language of the Computer

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

Chapter 2. Instruction Set Architecture (ISA)

Topic Notes: MIPS Instruction Set Architecture

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

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

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

Chapter 2. Instructions: Language of the Computer

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

Computer Architecture

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

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

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

MIPS%Assembly% E155%

Transcription:

CS3350B Computer Architecture Winter 2015 Lecture 4.2: MIPS ISA -- Instruction Representation Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted from lectures on Computer Organization and Design, Patterson & Hennessy, 5 th edition, 2013]

Representing Instructions 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! Register numbers $t0 $t7 are reg s 8 15 $t8 $t9 are reg s 24 25 $s0 $s7 are reg s 16 23 2

Overview: MIPS R3000 ISA Instruction Categories Computational Load/Store Jump and Branch Floating Point coprocessor Memory Management Special Registers R0 - R31 PC HI LO 3 Basic Instruction Formats: all 32 bits wide OP OP rs rt rd sha funct rs rt immediate R-format I-format OP jump target J-format 3

MIPS ISA Selected Instruction Set Category Instr OP/funct Example Meaning Arithmetic add R 0/32 add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract R 0/34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 add immediate I 8 addi $s1, $s2, 6 $s1 = $s2 + 6 or immediate I 13 ori $s1, $s2, 6 $s1 = $s2 v 6 Data load word I 35 lw $s1, 24($s2) $s1 = Memory($s2+24) Transfer store word I 43 sw $s1, 24($s2) Memory($s2+24) = $s1 load byte I 32 lb $s1, 25($s2) $s1 = Memory($s2+25) store byte I 40 sb $s1, 25($s2) Memory($s2+25) = $s1 load upper imm I 15 lui $s1, 6 $s1 = 6 * 2 16 Cond. br on equal I 4 beq $s1, $s2, L if ($s1==$s2) go to L Branch br on not equal I 5 bne $s1, $s2, L if ($s1!= $s2) go to L set on less than R 0/42 slt $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than immediate I 10 slti $s1, $s2, 6 if ($s2<6) $s1=1 else $s1=0 Uncond. jump J 2 j 250 go to 1000 Jump jump register R 0/8 jr $t1 go to $t1 jump and link J 3 jal 250 go to 1000; $ra=pc+4 4

MIPS R-format Instructions op rs rt rd shamt funct 6bit bits 5bit bits 5bit bits 5bit bits 5bit bits 6bit bits 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) 5

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

MIPS I-format Instructions op rs rt constant or address 6bit bits 5bit bits 5bit bits 16 bits 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 7

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 8

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 9

Shift Operations op rs rt rd shamt funct 6bit bits 5bit bits 5bit bits 5bit bits 5bit bits 6bit bits 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) 10

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

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

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 13

Conditional Operations Branch to a labeled instruction if a condition o 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 unconditional jump to instruction labeled L1 14

Compiling If Statements C code: if (i==j) f = g+h; else f = g-h; f, g, in $s0, $s1, Compiled MIPS code: bne $s3, $s4, Else add $s0, $s1, $s2 j Exit Else: sub $s0, $s1, $s2 Exit: Assembler calculates addresses 15

Compiling Loop Statements C code: 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: 16

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 17

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 18

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 19

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 20

Byte/Halfword Operations Could use bitwise operations MIPS byte/halfword load/store String processing is a common case lb rt, offset(rs) lh rt, offset(rs) Sign extend to 32 bits in rt lbu rt, offset(rs) lhu rt, offset(rs) Zero extend to 32 bits in rt sb rt, offset(rs) sh rt, offset(rs) Store just rightmost byte/halfword 21

Operand Addressing Modes (1) Register addressing operand is in a register op rs rt rd funct In register rs Example: add $rd, $rs, $rt # $rd = $rs + $rt word operand (2) Base (displacement) addressing operand is at the memory location whose address is the sum of a register and a 16-bit constant contained within the instruction op rs rt offset At memory $rs+offset word or byte operand base register Example: lw $rt, offset($rs) # $rt = Memory($rs+offset) Register relative (indirect) with 0($a0) (that is, offset = 0 ), or jr Pseudo-direct with addr($zero), that is, $rs = $zero = 0 22

Operand Addressing Modes (ctn d) (3) Immediate addressing operand is a 16-bit constant contained within the instruction op rs rt operand Example: addi $rt, $rs, operand # $rt = $rs + operand 23

Instruction Addressing Modes (1) PC-relative addressing instruction address is the sum of the PC and a 16-bit constant contained within the instruction op rs rt offset Program Counter (PC) Memory branch destination instruction Used for beq and bne: # if rs==rt (or rs!=rt), go to offset (PC=PC+4+4*offset) 4* (2) Pseudo-direct addressing instruction address is the 26-bit constant contained within the instruction concatenated with the upper 4 bits of the PC op jump address Program Counter (PC) Memory jump destination instruction Used for j (jump): PC xxxx jump address 00 24

Addressing Mode Summary 25

Caution: Addressing mode is not Instruction Types Addressing mode is how an address (memory or register) is determined. Instruction type is how the instruction is put together. Example: addi, beq, and lw are all I-Format instructions. ti But, addi uses immediate addressing mode (and register) beq uses pc-relative addressing (and register) lw uses base addressing (and register) 26

Summary of MIPS Addressing Modes Register: a source or destination operands specified as content of one of the registers $0-$31. Immediate: a numeric value embedded d in the instruction ti is the actual operand. PC-relative: a data or instruction memory location is specified as an offset relative to the incremented PC. Base: a data or instruction memory location is specified as a signed offset from a register. Register-direct: the value of the effective address is in a register. Pseudo-direct: di the memory address is (mostly) embedded d in the instruction. 27

MIPS Organization So Far src1 addr 5 src2 addr 5 dst addr 5 write data 32 Processor Register File 32 registers ($zero - $ra) 32 bits 32 32 src1 data src2 data read/write addr 32 Memory 1 1100 2 30 words Exec branch offset 32 32 PC 32 Add 32 4 Fetch 32 PC = PC+4 Decode 32 32 Add 32 ALU 32 read data write data 32 32 0 1100 0 1000 6 7 0 01000100 0 0000 32 bits word address (binary) 4 5 0 1 2 3 byte address (big Endian) 28

Concluding Remarks Design principles 1. Simplicity favors regularity 2. Smaller is faster 3. Make the common o case fast 4. Good design demands good compromises Layers of software/hardware Compiler, assembler, hardware MIPS: typical of RISC ISAs c.f. x86 29

Aside: Byte Addresses Since 8-bit bytes are so useful, most architectures address individual bytes in memory: byte-addressable it means that a byte is the smallest unit with its address Naturally aligned data: doublewords that lie on addresses that are multiples of eight, words that lie on addresses that are multiples of four, halfwords that lie on addresses that are multiples of two, and single bytes that lie at any byte address. Such data is located on its natural size boundary, to maximize storage potential and to provide for fast, efficient memory access. Little Endian: rightmost byte is word address Intel 80x86, DEC Vax, DEC Alpha (Windows NT) Big Endian: leftmost byte is word address IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA MIPS memory is byte-addressable; supports 32-bit address (an address is given as a 32-bit unsigned integer) 30

Aside: Compiler storage of data objects by byte alignment Type Bytes Alignment char, bool 1 Located at any byte address. short 2 float, int, long, pointer 4 long long, double, long double 8 Located at any address that is evenly divisible by 2. Located at an address that is evenly divisible i ibl by 4. Located at an address that is evenly divisible by 8. 31