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

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

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

Communicating with People (2.8)

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

Chapter 2. Instruction Set Architecture (ISA)

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instruction Set Architectures

Systems Architecture I

History of the Intel 80x86

Instruction Set Architecture. "Speaking with the computer"

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

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

Lecture 3: Instruction Set Architecture

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

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

ECE 486/586. Computer Architecture. Lecture # 8

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

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

ENE 334 Microprocessors

Chapter 2: Instructions:

CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14

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

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

Instruction Set Design and Architecture

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

1 5. Addressing Modes COMP2611 Fall 2015 Instruction: Language of the Computer

The Instruction Set Architecture (ISA)

Chapter 3. Instructions:

CS/COE1541: Introduction to Computer Architecture

ECE369. Chapter 2 ECE369

MIPS (SPIM) Assembler Syntax

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

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

Instruction Set Principles. (Appendix B)

Chapter 2A Instructions: Language of the Computer

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

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

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

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

Instructions: Language of the Computer

Computer Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Computer Systems Laboratory Sungkyunkwan University

Course Administration

Computer Organization MIPS ISA

LECTURE 2: INSTRUCTIONS

CENG3420 Lecture 03 Review

CS222: MIPS Instruction Set

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

CS3350B Computer Architecture MIPS Introduction

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC)

Computer Architecture. The Language of the Machine

Topic Notes: MIPS Instruction Set Architecture

CS3350B Computer Architecture

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

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

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

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

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 )

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

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

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

Control Instructions

Rechnerstrukturen. Chapter 2. Instructions: Language of the Computer

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

COE608: Computer Organization and Architecture

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

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

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

Lecture 4: MIPS Instruction Set

Chapter 2. Instructions: Language of the Computer

Review of instruction set architectures

Thomas Polzer Institut für Technische Informatik

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

Chapter 2. Instructions:

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

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

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

We will study the MIPS assembly language as an exemplar of the concept.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS3350B Computer Architecture MIPS Procedures and Compilation

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

Computer Architecture. MIPS Instruction Set Architecture

COMPUTER ORGANIZATION AND DESIGN

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

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

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

Lectures 3-4: MIPS instructions

Introduction to IA-32. Jo, Heeseung

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

INTRODUCTION TO IA-32. Jo, Heeseung

Levels of Programming. Registers

Transcription:

Chapter 2 1 MIPS Instructions Instruction Meaning add $s1,$s2,$s3 $s1 = $s2 + $s3 sub $s1,$s2,$s3 $s1 = $s2 $s3 addi $s1,$s2,4 $s1 = $s2 + 4 ori $s1,$s2,4 $s2 = $s2 4 lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1 bne $s4,$s5,label Next instr. is at Label if $s4 $s5 beq $s4,$s5,label Next instr. is at Label if $s4 = $s5 slt $t1,$s2,$s3 if $s2 < $s3, $t1 = 1 else $t1 = 0 j Label Next instr. is at Label jr $s1 Next instr is in register $s1 jal Label Jump and link procedure at Label 2

Assembly Language vs. Machine Language Assembly provides convenient symbolic representation much easier than writing down numbers e.g., destination first Machine language is the underlying reality e.g., destination is no longer first Assembly can provide 'pseudoinstructions' e.g., move $t0, $t1 exists only in Assembly would be implemented using add $t0,$t1,$zero 3 Stored Program Concept Instructions are bits Programs are stored in memory to be read or written just like data Processor Memory memory for data, programs, compilers, editors, etc. Fetch & Execute Cycle Instructions are fetched and put into a special register Bits in the register "control" the subsequent actions Fetch the next instruction and continue 4

Instruction Set Architecture: What Must be Specified? Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Instruction Format or Encoding how is it decoded? Location of operands and result where other than memory? how many explicit operands? how are memory operands located? which can or cannot be in memory? Data type and Size Operations what are supported Successor instruction jumps, conditions, branches - fetch-decode-execute is implicit! 5 MIPS Design Principles Reduced Instruction Set Computers (RISC) design philosophy Principles guiding Instruction Set Design Smaller is faster Example: Only 32 registers in MIPS Simplicity favors regularity Good design demands compromise Make the common case fast 6

Machine Language: R Format Instructions, like registers and words of data, are also 32 bits long Example: add $t0, $s1, $s2 registers have numbers, $t0=9, $s1=17, $s2=18 Instruction Format: 000000 10001 10010 01000 00000 100000 op rs rt rd shamt funct R Format 7 Machine Language: I format Consider the load-word and store-word instructions, What would the regularity principle have us do? New principle: Good design demands a compromise Introduce a new type of instruction format I-type for data transfer instructions other format was R-type for register Example: lw $t0, 32($s2) 35 18 9 32 op rs rt 16 bit number Where's the compromise? 8

Machine Language: J Format Jump (j), Jump and link (jal) instructions have two fields Opcode Address Instruction should be 32 bits (Regularity principle) 6 bits for opcode 26 bits for address J op 26 bit address 9 MIPS Instruction Formats simple instructions all 32 bits wide very structured, no unnecessary baggage only three instruction formats R I J op rs rt rd shamt funct op rs rt 16 bit address op 26 bit address 10

What about other instructions slt $t0, $s1, $s2 3 operands all registers use R format beq $s1,$s2, Label 2 registers + address use I format addi $s1,$s1, 4 2 registers + immediate value use I format jr $t1 1 register R format 11 Implications of design choices Using I format for arithmetic instructions with immediate operands Only 16 bits for immediate field Constants have to fit in 16 bits Using I format for branch instructions Only 16 bits in immediate field But 32 bits needed for branch address J format Only 26 bits for address field But 32 bits needed for Jump address 12

Constants Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; So in most programs, constants will fit in 16 bits allocated for immediate field Design Principle: Make the common case fast Common case: constant is small Only need to use one instruction in the common case 13 3 How about larger constants? We'd like to be able to load a 32 bit constant into a register Must use two instructions, new "load upper immediate" instruction lui $t0, 1010101010101010 filled with zeros 1010101010101010 0000000000000000 Then must get the lower order bits right, i.e., ori $t0, $t0, 1010101010101010 1010101010101010 0000000000000000 ori 0000000000000000 1010101010101010 1010101010101010 1010101010101010 14

Addresses in Branches and Jumps Instructions: bne $t4,$t5,label Next instruction is at Label if $t4 $t5 beq $t4,$t5,label Next instruction is at Label if $t4 = $t5 j Label Next instruction is at Label Formats: I J op rs rt 16 bit address op 26 bit address Addresses are not 32 bits How do we handle this with load and store instructions? 15 Addresses in Branches Instructions: bne $t4,$t5,label beq $t4,$t5,label Formats: Next instruction is at Label if $t4 $t5 Next instruction is at Label if $t4=$t5 I op rs rt 16 bit address Could specify a register (like lw and sw) and add it to address use Instruction Address Register (PC = program counter) most branches are local (principle of locality) Jump instructions just use high order bits of PC address boundaries of 256 MB 16

Addressing in branches Immediate field is 16 bits but we need an address that is 32 bits Obtain address using PC-relative addressing On branch, new PC = PC + immediate field in branch instruction Actually, new PC = (PC+4) + immediate field in branch instruction 80000 Loop: mult $9, $19, $10 80004 lw $8, Sstart($9) 80008 bne $8, $21, Exit 80012 add $19,$19,$20 80016 j Loop 80020 Exit: Immediate field contains the distance in words between PC+4 and branch target address 5 8 21 2 op rs rt address I format 17 Uncommon Case for branches beq $18, $19, L1 replaced by bne $18, $19, L2 j L1 L2: Make the common case fast one instruction for most branches 18

Addressing in Jumps J format has 26 bits in address field How to get 32 bits? Assume that jump address is a word address 26 + 2 (least significant bits) = 28 Get 4 most significant bits from PC 4 + 26 + 2 = 32 Implication: can only jump within a 2 28 = 256 MB block of addresses Loader and linker must be careful to avoid placing a program across an address boundary of 256 MB 19 To summarize: MIPS operands Name Example Comments $s0-$s7, $t0-$t9, $zero, Fast locations for data. In MIPS, data must be in registers to perform 32 registers $a0-$a3, $v0-$v1, $gp, arithmetic. MIPS register $zero always equals 0. Register $at is $fp, $sp, $ra, $at reserved for the assembler to handle large constants. Memory[0], Accessed only by data transfer instructions. MIPS uses byte addresses, so 2 30 memory Memory[4],..., sequential words differ by 4. Memory holds data structures, such as arrays, words Memory[4294967292] and spilled registers, such as those saved on procedure calls. MIPS assembly language Category Instruction Example Meaning Comments add add $s1, $s2, $s3 $s1 = $s2 + $s3 Three operands; data in registers Arithmetic subtract sub $s1, $s2, $s3 $s1 = $s2 - $s3 Three operands; data in registers add immediate addi $s1, $s2, 100 $s1 = $s2 + 100 Used to add constants load word lw $s1, 100($s2) $s1 = Memory[$s2 + 100] Word from memory to register store word sw $s1, 100($s2) Memory[$s2 + 100] = $s1 Word from register to memory Data transfer load byte lb $s1, 100($s2) $s1 = Memory[$s2 + 100] Byte from memory to register store byte sb $s1, 100($s2) Memory[$s2 + 100] = $s1 Byte from register to memory load upper immediate lui $s1, 100 16 $s1 = 100 * 2 Loads constant in upper 16 bits branch on equal beq $s1, $s2, 25 if ($s1 == $s2) go to PC + 4 + 100 Equal test; PC-relative branch branch on not equal bne $s1, $s2, 25 if ($s1!= $s2) go to PC + 4 + 100 Conditional branch set on less than slt $s1, $s2, $s3 if ($s2 < $s3) $s1 = 1; else $s1 = 0 set less than immediate slti $s1, $s2, 100 if ($s2 < 100) $s1 = 1; else $s1 = 0 Not equal test; PC-relative Compare less than; for beq, bne Compare less than constant jump j 2500 go to 10000 Jump to target address Uncondi- jump register jr $ra go to $ra For switch, procedure return tional jump jump and link jal 2500 $ra = PC + 4; go to 10000 For procedure call 20

1. Immediate addressing op rs rt Immediate 2. Register addressing op rs rt rd... funct Registers Register 3. Base addressing op rs rt Address Memory Register + Byte Halfword Word 4. PC-relative addressing op rs rt Address Memory PC + Word 5. Pseudodirect addressing op Address Memory PC Word 21 Alternative Architectures Design alternative: provide more powerful operations goal is to reduce number of instructions executed danger is a slower CPU Sometimes referred to as RISC vs. CISC virtually all new instruction sets since 1982 have been RISC VAX: minimize code size, make assembly language easy instructions from 1 to 54 bytes long! We ll look at PowerPC and IA-32 22

PowerPC Indexed addressing example: lw $t1,$a0+$s3 #$t1=memory[$a0+$s3] What do we have to do in MIPS? Update addressing update a register as part of load (for marching through arrays) example: lwu $t0,4($s3) #$t0=memory[$s3+4];$s3=$s3+4 What do we have to do in MIPS? Others: load multiple/store multiple a special counter register bc Loop decrement counter, if not 0 goto loop 23 IA - 32 1978: The Intel 8086 is announced (16 bit architecture) 1980: The 8087 floating point coprocessor is added 1982: The 80286 increases address space to 24 bits, +instructions 1985: The 80386 extends to 32 bits, new addressing modes 1989-1995: The 80486, Pentium, Pentium Pro add a few instructions (mostly designed for higher performance) 1997: 57 new MMX instructions are added, Pentium II 1999: The Pentium III added another 70 instructions (SSE) 2001: Another 144 instructions (SSE2) 2003: AMD extends the architecture to increase address space to 64 bits, widens all registers to 64 bits and other changes (AMD64) 2004: Intel capitulates and embraces AMD64 (calls it EM64T) and adds more media extensions This history illustrates the impact of the golden handcuffs of compatibility adding new features as someone might add clothing to a packed bag an architecture that is difficult to explain and impossible to love 24

IA-32 Overview Complexity: Instructions from 1 to 17 bytes long one operand must act as both a source and destination one operand can come from memory complex addressing modes e.g., base or scaled index with 8 or 32 bit displacement Saving grace: the most frequently used instructions are not too difficult to build compilers avoid the portions of the architecture that are slow what the 80x86 lacks in style is made up in quantity, making it beautiful from the right perspective 25 IA-32 Registers and Data Addressing Registers in the 32-bit subset that originated with 80386 Name 31 EAX ECX EDX EBX ESP EBP ESI EDI Use 0 GPR 0 GPR 1 GPR 2 GPR 3 GPR 4 GPR 5 GPR 6 GPR 7 CS SS DS ES FS GS Code segment pointer Stack segment pointer (top of stack) Data segment pointer 0 Data segment pointer 1 Data segment pointer 2 Data segment pointer 3 EIP EFLAGS Instruction pointer (PC) Condition codes 26

IA-32 Register Restrictions Registers are not general purpose note the restrictions below 27 IA-32 Typical Instructions Four major types of integer instructions: Data movement including move, push, pop Arithmetic and logical (destination register or memory) Control flow (use of condition codes / flags ) String instructions, including string move and string compare 28

IA-32 instruction Formats Typical formats: (notice the different lengths) a. JE EIP + displacement 4 4 8 JE Condition Displacement b. CALL 8 32 CALL Offset c. MOV EBX, [EDI + 45] 6 1 1 8 8 MOV d w r/m Postbyte Displacement d. PUSH ESI 5 3 PUSH Reg e. ADD EAX, #6765 4 3 1 32 ADD Reg w Immediate f. TEST EDX, #42 7 1 8 32 TEST w Postbyte Immediate 29 Summary Design Principles: simplicity favors regularity smaller is faster good design demands compromise make the common case fast 30