MIPS Instructions Instructions: Language of the Machine

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
INSTRUCTION SET ARCHITECTURES
1 ECE462/562 ISA and Datapath Review Ali Akoglu. 2 Instruction Set Architecture A very important abstraction –interface between hardware and low-level.
1 ECE369 ECE369 Chapter 2. 2 ECE369 Instruction Set Architecture A very important abstraction –interface between hardware and low-level software –standardizes.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2 Instructions: Language of the Computer
Chapter 2.
1 Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow Very restrictive e.g., MIPS Arithmetic.
1 CSE SUNY New Paltz Chapter 3 Machine Language Instructions.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
1  2004 Morgan Kaufmann Publishers Chapter 2. 2  2004 Morgan Kaufmann Publishers Instructions: Language of the Machine We’ll be working with the MIPS.
©UCB CPSC 161 Lecture 5 Prof. L.N. Bhuyan
ISA-2 CSCE430/830 MIPS: Case Study of Instruction Set Architecture CSCE430/830 Computer Architecture Instructor: Hong Jiang Courtesy of Prof. Yifeng Zhu.
1  2004 Morgan Kaufmann Publishers Instructions: bne $t4,$t5,Label Next instruction is at Label if $t4≠$t5 beq $t4,$t5,Label Next instruction is at Label.
1 EGRE 426 Fall 09 Handout Pipeline examples continued from last class.
1 Computer Architecture COSC 3430 Lecture 3: Instructions.
1  1998 Morgan Kaufmann Publishers Machine Instructions: Language of the Machine Lowest level of programming, control directly the hardware Assembly instructions.
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Computer Architecture (CS 207 D) Instruction Set Architecture ISA.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
MIPS Instructions Instructions: Language of the Machine
Chapter 2 — Instructions: Language of the Computer — 1 Memory Operands Main memory used for composite data – Arrays, structures, dynamic data To apply.
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
EEL5708/Bölöni Lec 3.1 Fall 2006 Sept 1, 2006 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
1  1998 Morgan Kaufmann Publishers Instructions: Language of the Machine More primitive than higher level languages e.g., no sophisticated control flow.
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
Morgan Kaufmann Publishers
Instructions: Language of the Computer
ELEN 468 Advanced Logic Design
The University of Adelaide, School of Computer Science
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Instructions - Type and Format
Appendix A Classifying Instruction Set Architecture
Lecture 4: MIPS Instruction Set
CS170 Computer Organization and Architecture I
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
CSCI206 - Computer Organization & Programming
The University of Adelaide, School of Computer Science
Systems Architecture Lecture 5: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
Computer Architecture & Operations I
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
Computer Instructions
Computer Architecture
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
CSC3050 – Computer Architecture
CS352H Computer Systems Architecture
Systems Architecture I (CS ) Lecture 5: MIPS Instruction Set*
Presentation transcript:

MIPS Instructions Instructions: Language of the Machine Instruction set architecture - the attributes of a computer system seen by the programmer Attributes organization of programmable storage data types and data structures, encodings, representations instruction format, operands instruction set (operation code set) addressing modes, accessing data items and instructions exceptional (interrupt) conditions We’ll be working with the MIPS instruction set architectures. MIPS : A typical RISC machine, 50M MIPS chips sold, used in computers, printers, network cards, video game (Nintendo).

Why do we study MIPS Instruction Set Architecture ? Instruction set Number sold 80x86 > 50,000,000 MIPS > 50,500,000 PowerPC > 3,300,000 SPARC > 700,000 HP PA-RISC > 300,000 DEC Alpha > 200,000

millions of processors sold

Processor Performance Increase Intel Pentium 4/3000 DEC Alpha 21264A/667 DEC Alpha 21264/600 Intel Xeon/2000 DEC Alpha 5/500 DEC Alpha 4/266 DEC Alpha 5/300 DEC AXP/500 IBM POWER 100 HP 9000/750 IBM RS6000 MIPS M2000 SUN-4/260 MIPS M/120

Where is the Market? Millions of Computers

Power consumption – especially in the embedded market where battery life is important (and passive cooling) For power-limited applications, the most important metric is energy efficiency

Specification - bottom-up Instruction Format or Encoding How is it decoded ? Location of the 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 instruction fetch decode operand execute store result next instruction

RISC vs CISC RISC (reduced instruction set computer) instructions only load/store instructions access memory data (i.e., operands) must be in registers to perform operation each instruction roughly taking same amount of time simple addressing modes virtually all new instruction sets since 1982 have been RISC (M 68000 announced in year 1980) etc. CISC (complex instruction set computer) instructions alu/logic instructions access memory to fetch operands load/store instructions access memory some instructions’ execution time is much longer than other instructions complex addressing modes

RISC - Reduced Instruction Set Computer RISC philosophy fixed instruction lengths load-store instruction sets limited addressing modes limited operations MIPS, Sun SPARC, HP PA-RISC, IBM PowerPC, Intel (Compaq) Alpha, … Instruction sets are measured by how well compilers use them as opposed to how well assembly language programmers use them Design goals: speed, cost (design, fabrication, test, packaging), size, power consumption, reliability, memory space (embedded systems)

MIPS Instructions MIPS is a RISC machine programmable storage : 32 32-bit general purpose registers (GPR), represented as $0, $1, $2, ......, $31, the content of $0 is always 0. 230 memory words, such as Memory[0], Memory[4], etc Memory holds data structures such as arrays, and spilled registers MIPS uses byte addresses so sequential words differ by 4 32 32-bit floating point registers, paired for double precision What is a spilled register ? A variable is less commonly used and saved in memory rather than in registers

MIPS Addressing Mode Simple addressing modes All instructions 32 bits wide register addressing op rs rt rd -- -- ; rs, rt specify the operand (i.e., register number) directly op rs rt immediate ; immediate is the operand immediate addressing base addressing (base + offset or displacement) op rs rt immediate ; rs + immediate is the address where the operand is located PC-relative op rs rt immediate ;PC + immediate is the address

MIPS Instructions R type instruction no. of bits 6 5 5 5 5 6 op rs rt rd shamt funct no. of bits 6 5 5 5 5 6 Some arithmetic and logic instructions are R-type and $1, $2, $3 ; $1 = $2 & $3 add $1, $2, $3 ; $1 = $2 + $3 slt $1, $2, $3 ; if ($2 < $3) then $1 = 1; else $1 = 0 addu $1, $2, $3 ; add unsigned, no exceptions sub $1, $2, $3 ; subu $1, $2, $3 ; sub unsigned, no exceptions

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) MIPS compiler uses $s0, $s1, ... for registers that correspond to variables in C program and $t0, $t1, ... for temporary registers needed to compile a program

MIPS Arithmetic Another Example C code: A = B + C + D; E = F - A; MIPS code: add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0 Operand must be registers, only 32 registers provided Design Principle: smaller is faster. Why ?

Register vs. Memory Arithmetic instructions operands must be registers, only 32 registers provided Compiler associates variables with registers What about programs with lots of variables use memory to store variables when all registers are used. Memory 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. For MIPS, a word is 32 bits or 4 bytes. 230 words with byte addresses 0, 4, 8, . . . 232 - 4 232 bytes with byte addresses from 0 to 232 - 1 Words are aligned

MIPS Instructions I type instruction ; small constants are used frequently op rs rt immediate no.of bits 6 5 5 16 instruction examples add immediate addi $1, $2, 100; immediate = 100, rs = $2, rt = $1; op =8 ; $1 = $2 + 100 and immediate andi $1, $2, 100; immediate = 100, rs = $2, rt = $1; op = 12 ; $1 = $2 & 100 Good design demands good compromises. Where is the compromise here ? (rt used as destination reg.) (rt used as operand reg. in R type)

MIPS Instructions I type instructions lw $1, 100($3); rs = $3, immediate = 100, rt = $1 $1 = Memory[100 + $3] sw $1, 150($2); rs = $2, immediate = 150, rt = $1 Memory[$2 + 150] = $1 lui $1, 108; immediate = 108 rs = 0, rt = $1; load 108 into upper 16 bits of register $1, $1 = 108 x 216

MIPS Instructions J type instruction op target address no. of bits 6 26 jump instruction; j 10000; go to target address 10000 jal 10000; $31 = PC + 4; go to 10000; for procedure call, ; return address is saved in $31

MIPS Instructions Instructions for making decisions alter the control flow, change the “next” instruction to be executed beq $1, $2, L1; (I type ) go to the instruction labeled L1, if the value in $1 equals the value in $2 bne $3, $4, L1; (I type) go to the instruction labeled L1, if the value in $3 not equal the value in $4 example: C code if (i==j) h = i+j; MIPS code bne $s0, $s1, Label add $s3, $s0, $s1 ..... Label: ....

MIPS Instructions Control MIPS unconditional branch instructions: j label Example: if (i != j) beq $s4, $s5, Lab1 h = i + j; add $s3, $s4, $s5 else j Lab2 h = i - j; Lab1: sub $s3, $s4, $s5 Lab2: ............ Other cases such as compiling a while loop, a switch statement, a loop with array index, a procedure call, nested procedures into MIPS code (skip, this is too much into assembly language programming) This course is to design a processor

Addressing Objects Big Endian: address of most significant byte = word address, (xxx...00 = big end of the word) IBM, Motorola 68K, MIPS, Sparc, HP PA Little Endian: address of least significant byte = word address, (xxx...00 = little end of the word) Intel 80x86, DEC Vax, DEC Alpha alignment : require that objects fall on address that is multiple of their size leftmost byte is word address Big Endian byte 0 byte 1 byte 2 byte 3 word 0 word 0 byte 3 byte 2 byte 1 byte 0 Little Endian rightmost byte is word address

Byte Addresses Since 8-bit bytes are so useful, most architectures address individual bytes in memory The memory address of a word must be a multiple of 4 (alignment restriction) Big Endian: leftmost byte is word address IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA Little Endian: rightmost byte is word address Intel 80x86, DEC Vax, DEC Alpha (Windows NT) msb lsb 3 2 1 0 little endian byte 0 0 1 2 3 big endian byte 0

Data Types Bit Bit String: Character: ASCII 7 bit code 4 bits is a nibble 8 bits is a byte 16 bits is a half word 32 bits is a word 64 bits is a double-word Character: ASCII 7 bit code Decimals : digits 0-9 encoded as 0000 through 1001 Integers : 2’s complement Floating Point: single precision, double precision

MIPS Instructions MIPS arithmetic instructions add, addi, addu, sub, subi, subu, addiu all arithmetic operations operate on words Which add for address arithmetic ? Which add for integers ?

MIPS Instructions Logical Instructions and, or, xor, nor, andi (and immediate), ori (or immediate), sll (shift left logical), srl (shift right logical), sra (shift right arithmetic), examples sll $1, $2, 10 ; $1 = $2 << 10 (shift left logical 10 bits of $2) srl $1, $2, 10 ; $1 = $2 >> 10 (shift right logical 10 bit) or $1, $2, $3 ; $1 = $2 | $3 and $1, $2, $3 ; $1 = $2 & $3 ori $2, $3, 99 : $2 = $3 | 99

MIPS Instructions data transfer instructions lw load word sw store word lbu load byte unsigned sb store byte lui load upper immediate lui $1, 100 ; $1 = 100 x 216 load 100 into the upper 16 bits of $1,

MIPS Instructions slt set on less than, compare 2’s comp. slt $1, $2, $3; if $2 < $3 then $1 = 1 else $1 = 0. slti set on less than immediate, compare 2’s comp. slti $2, $3, 79; if $3 < 79 then $2 = 1, else $2 = 0 sltu set on less than unsigned, compare natural numbers sltiu set on less than immediate unsigned, compare natural numbers jr jump register, jr $31 ; go to register $31

MIPS Instructions Signed vs Unsigned Comparison $1 = 0000 0000 0000...... 00001 $2 = 1111 1111 1111....... 11111 $3 = 0000 0000 0000........ 00000 slt $4, $1, $2 sltu $5, $1, $2 slt $6, $2, $3 sltu $7, $2, $3 $4=___________; $5 = ____________ $6=___________; $7 = _____________

MIPS Instructions $0 is always zero (you can not change it) branch and link save the return address PC+4 into $31 all instructions change all 32 bits of the destination register logic immediates are zero extended to 32 bits arithmetic immediates are sign extended to 32 bits data loaded by the instructions lb, lh are extended as follows: lbu, lhu are zero extended (unsigned load) lb, lh are sign extended overflow can occur in signed arithmetic/logic instructions, will not occur in unsigned arithmetic/logic instructions.

MIPS Summary fixed instruction format (3 formats: R, I, J) 3-address, reg-reg arithmetic/logical instructions single addressing mode for load/store instructions base + displacement simple branch conditions compare against zero or two registers for equal, not_equal, no integer condition code delayed branch (more examples in chapter 6) execute instruction after the branch (or jump) even if the branch is not taken. compiler fills a delayed branch with a useful instruction (50% correct). Three design principles: Simplicity favors regularity Smaller is faster Good design demands good compromises

All Time Popular Instruction Set - 80x86 1978: 8086 is announced (16 bit architecture) 1980: 8087 floating point coprocessor is added 1982: 80286 increases address space to 24 bits + some instructions 1985: 80386 extends to 32 bits, new addressing modes 1989 - 1995: 80486, Pentium, Pentium Pro add a few instructions, mostly designed for higher performance 1997: MMX is added 1999: Intel added another 70 instructions labelded as SSE (Streaming SIMD Extensions) as part of Pentium III 2001: Intel added another 144 instructions as SSE II 2003: IA-32 (but AMD announced AMD64) 2004: Intel capitulates and embraces AMD64.

All Time Popular Instruction Set: 80x86 Complexity of 80x86 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 This history illustrates the impact of the “golden handcuffs” of compatibility on 80x86. The existing software base was too important to jeopardize with significant architectural changes.

MIPS Summary more powerful instructions mean higher performance T F writing assembly language in order to obtain the highest performance T F smaller is faster T F simplicity favors regularity T F good design demands compromise T F make the common case fast T F evaluate instruction sets design time metrics : how long at what cost to implement static metrics : how many bytes program occupy memory dynamic metrics: