Lecture 3 Machine Language. Instructions: Instruction Execution cycle. Speaking computer before voice recognition interfaces

Similar documents
Instruction Set Architecture. "Speaking with the computer"

Chapter 2 Instruction: Language of the Computer

Chapter 2: Instructions How we talk to the computer

Instruction Set Architectures

EC-801 Advanced Computer Architecture

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

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

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

Lecture 4: Instruction Set Architecture

ECE 486/586. Computer Architecture. Lecture # 7

Chapter 3. Instructions:

Instruction Set Architectures. Part 1

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

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

Instruction Set Design

Chapter 2. Instructions:

Instruction Set Architecture (ISA)

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

Instruction Set Principles and Examples. Appendix B

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

CSEE 3827: Fundamentals of Computer Systems

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

Evolution of ISAs. Instruction set architectures have changed over computer generations with changes in the

Chapter 2. Instruction Set Design. Computer Architectures. software. hardware. Which is easier to change/design??? Tien-Fu Chen

Lecture 3: Instruction Set Architecture

Typical Processor Execution Cycle

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Chapter 2: Instructions:

ECE232: Hardware Organization and Design

CS222: MIPS Instruction Set

Chapter 2A Instructions: Language of the Computer

CSCE 5610: Computer Architecture

Instructions: Language of the Computer

Computer Architecture and Organization. Instruction Sets: Addressing Modes and Formats

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

Topic Notes: MIPS Instruction Set Architecture

Instructions: Language of the Computer

RISC, CISC, and ISA Variations

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

Computer Organization MIPS ISA

IC220 SlideSet #2: Instructions (Chapter 2)

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Computer Architecture

CS4617 Computer Architecture

The MIPS Instruction Set Architecture

COSC 6385 Computer Architecture. Instruction Set Architectures

CMSC Computer Architecture Lecture 2: ISA. Prof. Yanjing Li Department of Computer Science University of Chicago

Instruction Set Design and Architecture

EC 413 Computer Organization

CPU Architecture and Instruction Sets Chapter 1

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

CA226 Advanced Computer Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

EEC 581 Computer Architecture Lecture 1 Review MIPS

BASIC COMPUTER ORGANIZATION. Operating System Concepts 8 th Edition

Review of instruction set architectures

Hakim Weatherspoon CS 3410 Computer Science Cornell University

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

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

Page 1. Structure of von Nuemann machine. Instruction Set - the type of Instructions

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

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

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Reminder: tutorials start next week!

Addressing Modes. Immediate Direct Indirect Register Register Indirect Displacement (Indexed) Stack

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture. MIPS Instruction Set Architecture

INSTITUTO SUPERIOR TÉCNICO. Architectures for Embedded Computing

Lecture 4: ISA Tradeoffs (Continued) and Single-Cycle Microarchitectures

ECE369. Chapter 2 ECE369

CHAPTER 5 A Closer Look at Instruction Set Architectures

CS/COE1541: Introduction to Computer Architecture

Lecture 4: MIPS Instruction Set

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

Computer Hardware Generations

ISA: The Hardware Software Interface

ECE 486/586. Computer Architecture. Lecture # 8

CHAPTER 5 A Closer Look at Instruction Set Architectures

Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles.

Outline. What Makes a Good ISA? Programmability. Implementability

Instruction Set Architecture

Instruction Set Principles. (Appendix B)

Hardware Level Organization

Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University. See P&H Appendix , and 2.21

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

Lecture 4: RISC Computers

Processor Architecture. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

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

I ve been getting this a lot lately So, what are you teaching this term? Computer Organization. Do you mean, like keeping your computer in place?

Course Administration

Instruction Sets Ch 9-10

Instruction Sets Ch 9-10

CHAPTER 5 A Closer Look at Instruction Set Architectures

Review: What is a Computer?

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

ECE232: Hardware Organization and Design

Transcription:

Lecture 3 Machine Language Speaking computer before voice recognition interfaces 1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic Instructions 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 2 Instruction Execution cycle Instruction Fetch Obtain instruction from program storage Instruction Decode Determine required actions and instruction size Operand Fetch Execute Locate and obtain operand data Compute result value or status Result Store Next Instruction Deposit results in storage for later use Determine successor instruction 3

Key ISA decisions operations how many? which ones operands how many? location types how to specify? instruction format size how many formats? destination operand y = x + b operation (add r1, r2, r5) how does the computer know what 0001 0100 1101 1111 means? source operands 4 In the end, we must have: Operations 011010010 Destination 000010010 Sources 1010 01010010100 What an architect can change: type of operations: add, branch, find roots of ax 2 +bx+c sources and destinations: memory, registers, I/O the way we see memory: program and data or separated To understand these trade-offs, let us make some designs! 5 Crafting an ISA-I Memory instructions Results of computations CPU Suppose: memory is very slow, 100 X slower than CPU, and also, REALLY expensive. What would you do: a)code the instructions in a simple way, so that decoding them in the CPU takes less hardware; b)code instructions so that they use less memory. Answer (b) seems to be in the good direction! 6

Crafting an ISA-II And what seems more reasonable: a)have few instructions, so that there are not too many options to the And again, what is more reasonable: 7 Remember An architect should ALWAYS have an eye on the available technology! When silicon memory came, the time difference was reduced, and Going to memory is easier, but there is still a large difference in speed; memory is cheaper, can have lots of it! Compiler can not use complex instructions. People are less and less programming using assembly (only time critical code or bad management) Crafting an ISA-III how those decisions were made in the design of the MIPS instruction set. MIPS, like SPARC, PowerPC, and Alpha AXP, is a RISC (Reduced Instruction Set Computer) ISA. fixed instruction length few instruction formats load/store architecture

Crafting an ISA-IV RISC architectures worked because they enabled pipelining. They continue to thrive because they enable parallelism (more on this in this course!). Changes on technology that allowed RISCs: memory speed and cost compiler technology increase New changes to come: many transistors more (increase cache, branch prediction, floating point, etc); low power applications: back to complex coding? extensive use of dynamic RAM: IRAM chips? reconfigurable devices? Java machines? 10 Crafting an ISA-V More on technology dependencies and design decisions during the course. 11 How Many Operands? Most instructions have three operands (e.g., z = x + y). Well-known ISAs specify 0-3 (explicit) operands per instruction. Operands can be specified implicitly or explicity. 12

How Many Operands? (basic ISA classes) Accumulator: 1 address add A acc acc + mem[a] Stack: 0 address add tos tos + next General Purpose Register: 2 address add A B A A + B (addressing might be more complex) 3 address add A B C A B + C Load/Store: 3 address add Ra Rb Rc Ra Rb + Rc load Ra Rb Ra mem[rb] store Ra Rb mem[rb] Ra 13 Comparing the Number of Instructions Code sequence for C = A + B for four classes of instruction sets: Stack Accumulator Register Register (register-memory) (load-store) Push A Load A ADD C, A, B Load R1,A Push B Add B Load R2,B Add Store C Add R3,R1,R2 Pop C Store C,R3 Watch! For a sequence of operations, who is favored? Try: a*b+c*d*g+h; again with only 2 registers 14 Instruction Length Variable: Fixed: Hybrid: 15

Instruction Length Variable-length instructions (Intel 80x86, VAX) require multi-step fetch and decode, but allow for a much more flexible and compact instruction set. Fixed-length instructions allow easy fetch and decode, and simplify pipelining and parallelism (believe me by now; see for yourself in the lab!). All MIPS instructions are 32 bits long. this decision impacts every other ISA decision we make because it makes instruction bits scarce. 16 Instruction Formats: the role of each bit Having many different instruction formats... complicates decoding uses instruction bits (to specify the format) VAX 11 instruction format 17 MIPS Instruction Formats 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits OP rs rt rd sa funct OP OP rs rt immediate target the opcode tells the machine which format so add r1, r2, r3 has opcode=0, rs=2, rt=3, rd=1, sa=0, funct=32, 000000 00010 00011 00001 00000 100000 18

Accessing the Operands operands are generally in one of two places: registers (32 int, 32 fp) memory (2 32 locations) registers are easy to specify close to the processor (fast access) the idea that we want to access registers whenever possible led to load-store architectures. normal arithmetic instructions only access registers only access memory with explicit loads and stores 19 Load-store architectures can do: add r1=r2+r3 and load r3, M(address) forces heavy dependence on registers, which is exactly what 20 A historical note Once upon a time, a big company invented a new microprocessor. It had NO registers at all, all operations were memory mapped. Since memory was slow, the microprocessor never sold very much, because the overall system performance was low. Although heads rolled, some engineers claimed that the memory would become faster, and a whole set of problems needed too many memory references. The company used the same design strategy, applied to problems that required too many memory accesses and designed a processor tuned to a specific field: Digital Signal Processing. They made a fortune! 21

MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B + C MIPS code: add $s0, $s1, $s2 (associated with variables by compiler;) 22 MIPS arithmetic Design Principle: simplicity favors regularity. Of course this complicates some things... Why? C code: A = B + C + D; E = F - A; MIPS code: add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0 Operands must be registers, only 32 registers provided Design Principle: smaller is faster. Why? 23 Registers vs. Memory Arithmetic instructions operands must be registers, Compiler associates variables with registers What about programs with lots of variables Control Input Memory Datapath Output Processor I/O 24

So, how do we get the operands? Addressing modes! - Register direct R3 - Immediate (literal) #25 - Direct (absolute) M[10000] - Register indirect M[R3] - Base+Displacement M[R3 + 10000] if register is the program counter, this is PC-relative - Base+IndexM[R3 + R4] - Scaled Index M[R3 + R4*d + 10000] - Autoincrement M[R3++] - Autodecrement M[R3 - -] - Memory Indirect M[ M[R3] ] 25 MIPS addressing modes register direct OP rs rt rd sa funct add $1, $2, $3 immediate OP rs rt immediate add $1, $2, #35 base + displacement lw $1, disp($2) rt rs immediate register indirect disp = 0 absolute (rs) = 0 26 Is this sufficient? Measurements on the VAX show that these addressing modes (immediate, direct, register indirect, and base+displacement) represent 88% of all addressing mode usage. Similar measurements show that 16 bits is enough for the immediate 75 to 80% of the time; and that 16 bits is enough of a displacement 99% of the time. 27

Memory Organization Viewed as a large, single-dimension array, with an address. A memory address is an index into the array "Byte addressing" means that the index points to a byte of memory. 0 8 bits of data 1 8 bits of data 2 8 bits of data 3 8 bits of data 4 8 bits of data 5 8 bits of data 6 8 bits of data... 28 Memory Organization For MIPS, a word is 32 bits or 4 bytes. 0 4 8 12... 32 bits of data 32 bits of data 32 bits of data 32 bits of data Registers hold 32 bits of data 2 32 bytes with byte addresses from 0 to 2 32-1 2 30 words with byte addresses 0, 4, 8,... 2 32-4 Words are aligned i.e., what are the least 2 significant bits of a word address? 29 What have we got so far for the MIPS ISA: Fixed 32-bit instructions 3 instruction formats 3-operand, load-store architecture 32 general purpose registers (R0=0), all 32-bits wide (word) register, immediate, and base+displacement addressing modes 30

Instructions Load and store instructions Example (A=array 100 words, base address is in $s3): C code: MIPS code: A[12] = h + A[8]; lw $t0, 32($s3) add $t0, $s2, $t0 sw $t0, 48($s3) Store word has destination last Remember arithmetic operands are registers, not memory! 31 More lw and sw G = h + A[I] A has 100 elements; base=$s3 G=$s1 h=$s2 I=$s4 add $t1, $s4, $s4 # temp reg $t1 = 2*I add $t1, $t1, $s4 # temp reg $t1 = 2*I # multiply y 4 because of byte addressing add $t1, $t1, $s3 # $t1 = address of A[I] (4*i+$s3) lw $t0, 0($t1) # $t0=a[i] add $s1, $s2, $t0 Notice: offset + base addressing is good for structures: one register points to the base, the offset can select the desired element. 32 Exercise: G[j]= h + A[I]; G and A have 100 positions; use $t0-9 as scratch registers; base address of G is in $s3, of A in $s4. 33

Remember: MIPS Instruction Meaning add $s1, $s2, $s3 $s1 = $s2 + $s3 sub $s1, $s2, $s3 34