Lecture 4: MIPS Instruction Set

Similar documents
Lecture 5: Procedure Calls

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

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

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

CS3350B Computer Architecture MIPS Instruction Representation

Chapter 2A Instructions: Language of the Computer

MIPS%Assembly% E155%

Unsigned Binary Integers

Unsigned Binary Integers

Levels of Programming. Registers

Topic Notes: MIPS Instruction Set Architecture

EC-801 Advanced Computer Architecture

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

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

Chapter 2. Instructions:

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

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

ECE232: Hardware Organization and Design

CSEE 3827: Fundamentals of Computer Systems

Computer Architecture

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

Chapter 2: Instructions:

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

CENG3420 Lecture 03 Review

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CS222: MIPS Instruction Set

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

Computer Architecture. Lecture 2 : Instructions

Instructions: Language of the Computer

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

Lectures 3-4: MIPS instructions

Course Administration

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

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

ECE 486/586. Computer Architecture. Lecture # 7

Instructions: Language of the Computer

Computer Organization MIPS ISA

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

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

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

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 AND DESIGN

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

Control Instructions

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

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

Chapter 2. Instructions: Language of the Computer

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

Computer Architecture

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

Computer Organization and Components

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

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

CS3350B Computer Architecture MIPS Introduction

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

Chapter 2. Instruction Set Architecture (ISA)

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

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

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

Chapter 3. Instructions:

CS61C - Machine Structures. Lecture 6 - Instruction Representation. September 15, 2000 David Patterson.

Instruction Set Architecture

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

ECE 154A Introduction to. Fall 2012

CS61C : Machine Structures

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

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

Reduced Instruction Set Computer (RISC)

EEC 581 Computer Architecture Lecture 1 Review MIPS

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

CS3350B Computer Architecture

CENG3420 L03: Instruction Set Architecture

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

CSCI 402: Computer Architectures

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

Reduced Instruction Set Computer (RISC)

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

Lecture 4: Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture

MIPS Instruction Set Architecture (2)

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Review of instruction set architectures

CS/COE1541: Introduction to Computer Architecture

The MIPS Instruction Set Architecture

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

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

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

LECTURE 2: INSTRUCTIONS

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

EC 413 Computer Organization

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

MIPS Coding Continued

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

MIPS (SPIM) Assembler Syntax

Instruction Set Architecture. "Speaking with the computer"

UCB CS61C : Machine Structures

Transcription:

Lecture 4: MIPS Instruction Set No class on Tuesday Today s topic: MIPS instructions Code examples 1

Instruction Set Understanding the language of the hardware is key to understanding the hardware/software interface A program (in say, C) is compiled into an executable that is composed of machine instructions this executable must also run on future machines for example, each Intel processor reads in the same x86 instructions, but each processor handles instructions differently Java programs are converted into portable bytecode that is converted into machine instructions during execution (just-in-time compilation) What are important design principles when defining the instruction set architecture (ISA)? 2

Instruction Set Important design principles when defining the instruction set architecture (ISA): keep the hardware simple the chip must only implement basic primitives and run fast keep the instructions regular simplifies the decoding/scheduling of instructions We will later discuss RISC vs CISC 3

A Basic MIPS Instruction C code: a = b + c ; Assembly code: (human-friendly machine instructions) add a, b, c # a is the sum of b and c Machine code: (hardware-friendly machine instructions) 00000010001100100100000000100000 Translate the following C code into assembly code: a = b + c + d + e; 4

Example C code a = b + c + d + e; translates into the following assembly code: add a, b, c add a, b, c add a, a, d or add f, d, e add a, a, e add a, a, f Instructions are simple: fixed number of operands (unlike C) A single line of C code is converted into multiple lines of assembly code Some sequences are better than others the second sequence needs one more (temporary) variable f 5

Subtract Example C code f = (g + h) (i + j); Assembly code translation with only add and sub instructions: 6

Subtract Example C code f = (g + h) (i + j); translates into the following assembly code: add t0, g, h add f, g, h add t1, i, j or sub f, f, i sub f, t0, t1 sub f, f, j Each version may produce a different result because floating-point operations are not necessarily associative and commutative more on this later 7

Operands In C, each variable is a location in memory In hardware, each memory access is expensive if variable a is accessed repeatedly, it helps to bring the variable into an on-chip scratchpad and operate on the scratchpad (registers) To simplify the instructions, we require that each instruction (add, sub) only operate on registers Note: the number of operands (variables) in a C program is very large; the number of operands in assembly is fixed there can be only so many scratchpad registers 8

Registers The MIPS ISA has 32 registers (x86 has 8 registers) Why not more? Why not less? Each register is 32-bit wide (modern 64-bit architectures have 64-bit wide registers) A 32-bit entity (4 bytes) is referred to as a word To make the code more readable, registers are partitioned as $s0-$s7 (C/Java variables), $t0-$t9 (temporary variables) 9

Memory Operands Values must be fetched from memory before (add and sub) instructions can operate on them Load word lw $t0, memory-address Register Memory Store word sw $t0, memory-address Register Memory How is memory-address determined? 10

Memory Address The compiler organizes data in memory it knows the location of every variable (saved in a table) it can fill in the appropriate mem-address for load-store instructions int a, b, c, d[10] Memory Base address 11

Immediate Operands An instruction may require a constant as input An immediate instruction uses a constant number as one of the inputs (instead of a register operand) Putting a constant in a register requires addition to register $zero (a special register that always has zero in it) -- since every instruction requires at least one operand to be a register For example, putting the constant 1000 into a register: addi $s0, $zero, 1000 12

Memory Instruction Format The format of a load instruction: destination register source address lw $t0, 8($t3) any register a constant that is added to the register in brackets 13

Memory Instruction Format The format of a store instruction: source register source address sw $t0, 8($t3) any register a constant that is added to the register in brackets 14

Example int a, b, c, d[10]; addi $t0, $zero, 1000 # assume that data is stored at # base address 1000; placed in $t0; # $zero is a register that always # equals zero lw $s1, 0($t0) # brings value of a into register $s1 lw $s2, 4($t0) # brings value of b into register $s2 lw $s3, 8($t0) # brings value of c into register $s3 lw $s4, 12($t0) # brings value of d[0] into register $s4 lw $s5, 16($t0) # brings value of d[1] into register $s5 15

Example Convert to assembly: C code: d[3] = d[2] + a; 16

Example Convert to assembly: C code: d[3] = d[2] + a; Assembly (same assumptions as previous example): lw $s0, 0($t0) # a is brought into $s0 lw $s1, 20($t0) # d[2] is brought into $s1 add $t1, $s0, $s1 # the sum is in $t1 sw $t1, 24($t0) # $t1 is stored into d[3] Assembly version of the code continues to expand! 17

Memory Organization The space allocated on stack by a procedure is termed the activation record (includes saved values and data local to the procedure) frame pointer points to the start of the record and stack pointer points to the end variable addresses are specified relative to $fp as $sp may change during the execution of the procedure $gp points to area in memory that saves global variables Dynamically allocated storage (with malloc()) is placed on the heap Stack Dynamic data (heap) Static data (globals) Text (instructions) 18

Recap Numeric Representations Decimal 35 10 = 3 x 10 1 + 5 x 10 0 Binary 00100011 2 = 1 x 2 5 + 1 x 2 1 + 1 x 2 0 Hexadecimal (compact representation) 0x 23 or 23 hex = 2 x 16 1 + 3 x 16 0 0-15 (decimal) 0-9, a-f (hex) Dec Binary Hex 0 0000 00 1 0001 01 2 0010 02 3 0011 03 Dec Binary Hex 4 0100 04 5 0101 05 6 0110 06 7 0111 07 Dec Binary Hex 8 1000 08 9 1001 09 10 1010 0a 11 1011 0b Dec Binary Hex 12 1100 0c 13 1101 0d 14 1110 0e 15 1111 0f 19

Instruction Formats Instructions are represented as 32-bit numbers (one word), broken into 6 fields R-type instruction add $t0, $s1, $s2 000000 10001 10010 01000 00000 100000 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits op rs rt rd shamt funct opcode source source dest shift amt function I-type instruction lw $t0, 32($s3) 6 bits 5 bits 5 bits 16 bits opcode rs rt constant 20

Logical Operations Logical ops C operators Java operators MIPS instr Shift Left << << sll Shift Right >> >>> srl Bit-by-bit AND & & and, andi Bit-by-bit OR or, ori Bit-by-bit NOT ~ ~ nor 21

Control Instructions Conditional branch: Jump to instruction L1 if register1 equals register2: beq register1, register2, L1 Similarly, bne and slt (set-on-less-than) Unconditional branch: j L1 jr $s0 (useful for large case statements and big jumps) Convert to assembly: if (i == j) f = g+h; else f = g-h; 22

Control Instructions Conditional branch: Jump to instruction L1 if register1 equals register2: beq register1, register2, L1 Similarly, bne and slt (set-on-less-than) Unconditional branch: j L1 jr $s0 (useful for large case statements and big jumps) Convert to assembly: if (i == j) bne $s3, $s4, Else f = g+h; add $s0, $s1, $s2 else j Exit f = g-h; Else: sub $s0, $s1, $s2 Exit: 23

Title Bullet 24