ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H. Lipasti. University of Wisconsin-Madison. Basics Registers and ALU ops

Similar documents
CSE 533: Advanced Computer Architectures Instructor: Gürhan Küçük. Instructions. Instructions cont d. Forecast. Basics. Basics

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

Computer Architecture. MIPS Instruction Set Architecture

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

Reduced Instruction Set Computer (RISC)

Introduction To Computer Architecture

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

Reduced Instruction Set Computer (RISC)

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

CENG3420 Lecture 03 Review

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Chapter 2A Instructions: Language of the Computer

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

Computer Architecture

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

CS222: MIPS Instruction Set

EEC 581 Computer Architecture Lecture 1 Review MIPS

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

Review of instruction set architectures

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

Computer Organization MIPS ISA

Computer Architecture. The Language of the Machine

CS3350B Computer Architecture MIPS Instruction Representation

EC 413 Computer Organization

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

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

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

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

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

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

Systems Architecture I

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

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

LECTURE 2: INSTRUCTIONS

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

Instructions: Language of the Computer

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

COMPUTER ORGANIZATION AND DESIGN

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

MIPS Assembly Programming

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

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

Computer Systems Laboratory Sungkyunkwan University

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

EE 361 University of Hawaii Fall

Reminder: tutorials start next week!

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

CS/COE1541: Introduction to Computer Architecture

Course Administration

CS3350B Computer Architecture MIPS Procedures and Compilation

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

CS 61c: Great Ideas in Computer Architecture

Instruction Set Architecture. "Speaking with the computer"

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

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

Chapter 2: Instructions:

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

Control Instructions

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

ISA: The Hardware Software Interface

Instruction Set Architecture

MIPS%Assembly% E155%

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

Lecture 4: Instruction Set Architecture

Lecture 5: Procedure Calls

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

Lecture 4: MIPS Instruction Set

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

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

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

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

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

Communicating with People (2.8)

Computer Architecture

Instruction Set Design and Architecture

Course Administration

Computer Organization and Components

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

CENG3420 L03: Instruction Set Architecture

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

Topic Notes: MIPS Instruction Set Architecture

Chapter 2. Baback Izadi Division of Engineering Programs

Instructions: Assembly Language

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

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

M2 Instruction Set Architecture

CS 4200/5200 Computer Architecture I

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

Programmable Machines

Thomas Polzer Institut für Technische Informatik

CSE Lecture In Class Example Handout

COE608: Computer Organization and Architecture

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Transcription:

ECE/CS 552: Instruction Sets Instructor:Mikko H. Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill. Instructions (354 Review) Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary This defines most of the interface to the processor (not quite everything) Implementations can and do vary Intel 486->Pentium->P6->Core Duo->Core i7 Instructions cont d MIPS ISA used in 552: Simple, sensible, regular, widely used Most common: x86 (IA-32) Intel Pentium/Core i7, AMD Athlon, etc. Others: PowerPC (Mac, IBM servers) SPARC (Sun) ARM (cell phones, embedded systems) We won t write programs in this course Forecast Basics Registers and ALU ops and load/store Branches and jumps Etc. Basics C statement f = (g + h) (i + j) MIPS instructions add t0, g, h add t1, i, j sub f, t0, t1 Opcode/mnemonic, operands, source/destination Basics Opcode: specifies the kind of operation (mnemonic) Operands: input and output data (source/destination) Operands t0 & t1 are temporaries One operation, two inputs, one output Multiple instructions for one C statement ECE/CS 552: Introduction To Computer Architecture 1

Why not bigger instructions? Why not f = (g + h) (i + j) as one instruction? Church s thesis: A very primitive computer can compute anything that a fancy computer can compute you need only logical functions, read and write memory, and data-dependent decisions Therefore, ISA selected for practical reasons: Performance and cost, not computability Regularity tends to improve both E.g. H/W to handle arbitrary number of operands is complex and slow and UNNECESSARY Registers and ALU ops Operands must be registers, not variables add $8, $17, $18 add $9, $19, $20 sub $16, $8, $9 MIPS has 32 registers $0-$31 $8 and $9 are temps, $16 is f, $17 is g, $18 is h, $19 is i and $20 is j MIPS also allows one constant called immediate Later we will see immediate is restricted to 16 bits Registers and ALU Registe ers Processor $0 $31 ALU ALU ops Some ALU ops: add, addi, addu, addiu (immediate, unsigned) sub mul, div wider result 32b x 32b = 64b product 32b / 32b = 32b quotient and 32b remainder and, andi or, ori sll, srl Why registers? Short name fits in instruction word: log 2 (32) = 5 bits But are registers enough? and Load/Store Need more than 32 words of storage An array of locations M[j] indexed by j Data movement (on words or integers) Load word for register <= memory lw $17, 1002 # get input g Store word for register => memory sw $16, 1001 # save output f and load/store Regis sters Processor $0 $31 ALU 0 1 2 3 1001 1002 maxmem f g ECE/CS 552: Introduction To Computer Architecture 2

and load/store Important for arrays A[i] = A[i] + h # $8 is temp, $18 is h, $21 is (i x 4) # Astart is &A[0] is 0x8000 lw $8, Astart($21) # or 8000($21) add $8, $18, $8 sw $8, Astart($21) MIPS has other load/store for bytes and halfwords Regis sters and load/store Processor $0 $31 ALU 0 4004 f 4008 g 8000 A[0] 8004 A[1] 8008 A[2] maxmem Aside on Endian Branches and Jumps Big endian: MSB at address xxxxxx00 E.g. IBM, SPARC Little endian: MSB at address xxxxxx11 E.g. Intel x86 Mode selectable E.g. PowerPC, MIPS While ( i!= j) { j= j + i; i= i + 1; } # $8 is i, $9 is j # $10 is k Loop: beq $8, $9, Exit add $9, $9, $8 addi $8, $8, 1 j Loop Exit: Branches and Jumps # better: beq $8, $9, Exit # not!= Loop: add $9, $9, $8 Exit: addi $8, $8, 1 bne $8, $9, Loop Best to let compilers worry about such optimizations Branches and Jumps What does bne do really? read $, read $9, compare Set PC = PC + 4 or PC = Target To do compares other than = or!= E.g. blt $8, $9, Target # pseudoinstruction Expands to: slt $1, $8, $9 # $1==($8<$9)==($8-$9)<0 bne $1, $0, Target # $0 is always 0 ECE/CS 552: Introduction To Computer Architecture 3

Branches and Jumps Other MIPS branches/jumps beq $8, $9, imm # if ($8==$9) PC = PC + imm<< 2 else PC += 4; bne slt, sle sgt, sge With immediate, unsigned j addr # PC = addr jr $12 # PC = $12 jal addr # $31 = PC + 4; PC = addr; used for??? MIPS Machine Language All instructions are 32 bits wide Assembly: add $1, $2, $3 Machine language: 33222222222211111111110000000000 10987654321098765432109876543210 00000000010000110000100000010000 000000 00010 00011 00001 00000 010000 alu-rr 2 3 1 zero add/signed Instruction Format R-format Opc rs rt rd shamt function 65 5 5 5 6 Digression: i How do you store the number 4,392,976? Same as add $1, $2, $3 Stored program: instructions are represented as numbers Programs can be read/written in memory like numbers Instruction Format Other R-format: addu, sub, subi, etc. Assembly: lw $1, 100($2) Machine: 100011 00010 00001 0000000001100100 lw 2 1 100 (in binary) Machine: 100011 00010 00001 0000000001100100 I-format Opc rs rt address/immediate 6 5 5 16 Instruction Format I-format also used for ALU ops with immediates addi $1, $2, 100 001000 00010 00001 0000000001100100 What about constants larger than 16 bits Outside range: [-32768, 32767]? 1100 0000 0000 0000 1111? lui $4, 12 # $4 == 0000 0000 1100 0000 0000 0000 0000 0000 ori $4, $4, 15 # $4 == 0000 0000 1100 0000 0000 0000 1111 All loads and stores use I-format Instruction Format beq $1, $2, 7 000100 00001 00010 0000 0000 0000 0111 PC = PC + (0000 0111 << 2) # word offset Finally, J-format J address Opcode addr 6 26 Addr is weird in MIPS: addr = 4 MSB of PC // addr // 00 ECE/CS 552: Introduction To Computer Architecture 4

Summary: Instruction Formats R: opcode rs rt rd shamt function 6 5 5 5 5 6 I: opcode rs rt address/immediate 6 5 5 16 J: opcode addr 6 26 Instruction decode: Read instruction bits Activate control signals Procedure Calls See section 2.8 for details Caller Save registers Set up parameters Call procedure Get results Restore registers Callee Save more registers Do some work, set up result Restore registers Return Jal is special, otherwise just software convention Procedure Calls Stack is all-important Stack grows from larger to smaller addresses (arbitrary) $29 is stack pointer; points just beyond valid data Push $2: addi $29, $29, -4 sw $2, 4($29) Pop $2: lw $2, 4($29) addi $29, $29, 4 Cannot change order. Why? Interrupts. Procedure Example Swap(int v[], int k) { int temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } # $4 is v[] & $5 is k -- 1st & 2nd incoming argument # $8, $9 & $10 are temporaries that callee can use w/o saving swap: add $9,$5,$5 # $9 = k+k add $9,$9,$9 # $9 = k*4 add $9,$4,$9 # $9 = v + k*4 = &(v[k]) lw $8,0($9) # $8 = temp = v[k] lw $10,4($9) # $10 = v[k+1] sw $10,0($9) # v[k] = v[k+1] sw $8,4($9) # v[k+1] = temp jr $31 # return There are many ways of accessing operands Register addressing: add $1, $2, $3 op rs rt rd... funct register Base addressing (aka displacement) lw $1, 100($2) # $2 == 400, M[500] == 42 op rs rt Offset/displacement register 400 100 Effective address 42 ECE/CS 552: Introduction To Computer Architecture 5

Immediate addressing addi $1, $2, 100 op rs rt immediate PC relative addressing beq $1, $2, 100 # if ($1==$2) PC = PC + 100 op rs rt address PC Effective address Not found in MIPS: Indexed: add two registers base + index Indirect: M[M[addr]] [ two memory references Autoincrement/decrement: add operand size Autoupdate found in PowerPC, PA-RISC Like displacement, but update base register Autoupdate lwupdate $1,24($2) # $1 = M[$2+24]; $2 = $2 + 24 op rs rt address Delay register Effective address for(i=0; i < N, i += 1) sum += A[i]; # $7 is sum, $8 is &a[i], $9 is N,$2 is tmp, $3 is i*4 Inner loop: Or: lw $2, 0($8) lwupdate $2, 4($8) addi $8, $8, 4 add $7, $7, $2 add $7, $7, $2 Where s the bug? Before loop: sub $8, $8, 4 How to Choose ISA Minimize what? Instrs/prog x cycles/instr x sec/cycle!!! In 1985-1995 technology, simple modes like MIPS were great As technology changes, computer design options change If memory is limited, dense instructions are important For high speed, pipelining and ease of pipelining is important ECE/CS 552: Introduction To Computer Architecture 6

Some Intel x86 (IA-32) History Year CPU Comment 1978 8086 16-bit with 8-bit bus from 8080; selected for IBM PC 1980 8087 Floating Point Unit 1982 80286 24-bit addresses, memory-map, protection ti 1985 80386 32-bit registers, flat memory addressing, paging 1989 80486 Pipelining 1992 Pentium Superscalar 1995 Pentium Out-of-order execution, 1997 MMX Pro 1999 P-III SSE streaming SIMD Intel 386 Registers & Registers 8 32b registers (but backward 16b & 8b: EAX, AX, AH, AL) 4 special registers: stack (ESP) & frame (EBP) Condition codes: overflow, sign, zero, parity, carry Floating point uses 8-element stack Flat 32b or segmented (rarely used) Effective address = (base_reg + (index_reg x scaling_factor) + displacement) Intel 386 ISA Two register instructions: src1/dst, src2 reg/reg, reg/immed, reg/mem, mem/reg, mem/imm Examples mov EAX, 23 # 32b 2 s C imm 23 in EAX neg [EAX+4] # M[EAX+4] = -M[EAX+4] faddp ST(7), ST # ST = ST + ST(7) jle label # PC = label if sign or zero flag set Intel 386 ISA cont d Decoding nightmare Instructions 1 to 17 bytes Optional prefixes,,postfixes alter semantics AMD64 64-bit extension: 64b prefix byte Crazy formats E.g. register specifiers move around But key 32b 386 instructions not terrible Yet entire ISA has to correctly implemented Current Approach Current technique used by Intel and AMD Decode logic translates to RISC uops Execution units run RISC uops Backward compatible Very complex decoder Execution unit has simpler (manageable) control logic, data paths We use MIPS to keep it simple and clean Learn x86 on the job! Complex Instructions More powerful instructions not faster E.g. string copy Option 1: move with repeat prefix for memory-to-memory move Special-purpose Option 2: use loads/stores to/from registers Generic instructions Option 2 faster on same machine! (but which code is denser?) ECE/CS 552: Introduction To Computer Architecture 7

Conclusions Simple and regular Constant length instructions, fields in same place Small and fast Small number of operands in registers Compromises inevitable Pipelining should not be hindered Make common case fast! Backwards compatibility! ECE/CS 552: Introduction To Computer Architecture 8