Instruction encoding. MIPS Instruction encoding

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

CS3350B Computer Architecture MIPS Instruction Representation

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

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

Course Administration

Examples of branch instructions

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

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

Computer Architecture

ECE260: Fundamentals of Computer Engineering

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

CS3350B Computer Architecture MIPS Introduction

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

ECE260: Fundamentals of Computer Engineering

Computer Organization MIPS ISA

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

Reduced Instruction Set Computer (RISC)

Instructions: Language of the Computer

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

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

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

Flow of Control -- Conditional branch instructions

Unsigned Binary Integers

Unsigned Binary Integers

Topic Notes: MIPS Instruction Set Architecture

MIPS (SPIM) Assembler Syntax

CS3350B Computer Architecture

Reduced Instruction Set Computer (RISC)

CSEE 3827: Fundamentals of Computer Systems

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

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

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

ECE 486/586. Computer Architecture. Lecture # 7

Lecture 4: MIPS Instruction Set

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

M2 Instruction Set Architecture

MIPS Instruction Set

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

ISA: The Hardware Software Interface

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

3. Instruction Set Architecture The MIPS architecture

CS 61c: Great Ideas in Computer Architecture

CS/COE1541: Introduction to Computer Architecture

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

Instructions: Language of the Computer

MIPS History. ISA MIPS Registers

MIPS Reference Guide

MIPS Assembly: More about Memory and Instructions CS 64: Computer Organization and Design Logic Lecture #7

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

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

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

MIPS%Assembly% E155%

Systems Architecture I

Operations, Operands, and Instructions

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


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

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

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

CENG3420 Lecture 03 Review

ECE 154A Introduction to. Fall 2012

Chapter 2. Instruction Set. RISC vs. CISC Instruction set. The University of Adelaide, School of Computer Science 18 September 2017

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

MIPS Assembly Programming

Chapter 2A Instructions: Language of the Computer

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

Computer Organization and Components

CPS311 - COMPUTER ORGANIZATION. A bit of history

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

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

Chapter 4. The Processor

Lectures 3-4: MIPS instructions

Chapter 2. Instruction Set Architecture (ISA)

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

Computer Architecture. The Language of the Machine

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

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Assembler. Lecture 8 CS301

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

CSSE 232 Computer Architecture I. I/O and Addressing

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

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

Computer Architecture. MIPS Instruction Set Architecture

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

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

The Processor: Datapath and Control. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Stack Memory. item (16-bit) to be pushed. item (16-bit) most recent

CS 4200/5200 Computer Architecture I

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

The MIPS Instruction Set Architecture

COMPUTER ORGANIZATION AND DESIGN

Course Administration

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

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

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

EE 109 Unit 8 MIPS Instruction Set

Transcription:

Instruction encoding The ISA defines The format of an instruction (syntax) The meaning of the instruction (semantics) Format = Encoding Each instruction format has various fields Opcode field gives the semantics (Add, Load etc ) Operand fields (rs,rt,rd,immed) say where to find inputs (registers, constants) and where to store the output 1/13/99 CSE378 Instr. encoding. 1 MIPS Instruction encoding MIPS = RISC hence Few (3+) instruction formats R in RISC also stands for Regular All instructions of the same length (32-bits = 4 bytes) Formats are consistent with each other Opcode always at the same place (6 most significant bits) rd and rs always at the same place immed always at the same place etc. 1/13/99 CSE378 Instr. encoding. 2 1

I-type (immediate) format An instruction with an immediate constant has the SPIM form: Opcode Operands Comment Addi $4,$7,78 #$4=$7 + 78 Opc rs rt immed Encoding of the 32 bits: Opcode is 6 bits Since we have 32 registers, each register name is 5 bits This leaves 16 bits for the immediate constant 1/13/99 CSE378 Instr. encoding. 3 I-type format example Addi $a0,$12,33 #$a0 is also $4 = $12 +33 #Addi has opcode 08 Opc rs rt immed 08 12 4 33 31 25 20 15 0 In hex: 21840021 1/13/99 CSE378 Instr. encoding. 4 2

Sign extension Internally the ALU (adder) deals with 32-bit numbers What happens to the 16-bit constant? Extended to 32 bits If the Opcode says unsigned (e.g., Addiu) Fill upper 16 bits with 0 s If the Opcode says signed (e.g., Addi) Fill upper 16 bits with the msb of the 16 bit constant i.e. fill with 0 s if the number is positive i.e. fill with 1 s if the number is negative 1/13/99 CSE378 Instr. encoding. 5 R-type (register) format Arithmetic, Logical, and Compare instructions require encoding 3 registers. Opcode (6 bits) + 3 registers (5.3 =15 bits) => 32-21 = 11 free bits Use 6 of these bits to expand the Opcode Use 5 for the shift amount in shift instructions Opc rs rt rd sht func 1/13/99 CSE378 Instr. encoding. 6 3

R-type example Sub $7,$8,$9 Opc =0, funct = 34 rs rt rd 0 8 9 7 0 34 1/13/99 CSE378 Instr. encoding. 7 Load and Store instructions MIPS= RISC = Load-Store architecture Load: brings data from memory to a register Store: brings data back to memory from a register Each load-store instruction must specify The unit of info to be transferred (byte, word etc. ) through the Opc The address in memory A memory address is a 32-bit byte address An instruction has only 32 bits so. 1/13/99 CSE378 Instr. encoding. 8 4

Addressing in Load/Store instructions The address will be the sum of a base register (register rs) a 16-bit offset (or displacement) which will be in the immed field and is added (as a signed number) to the contents of the base register Thus, one can address any byte within ± 32KB of the address pointed to by the contents of the base register. 1/13/99 CSE378 Instr. encoding. 9 Examples of load-store instructions Load word from memory: Lw rt,rs,offset #rt = Memory[rs+offset] Store word to memory: Sw rt,rs,offset #Memory[rs+offset]=rt For bytes (or half-words) only the lower byte (or halfword) of a register is addressable For load you need to specify if it is sign-extended or not Lb rt,rs,offset #rt =sign-ext( Memory[rs+offset]) Lbu rt,rs,offset #rt =zero-ext( Memory[rs+offset]) Sb rt,rs,offset #Memory[rs+offset]= least signif. #byte of rt 1/13/99 CSE378 Instr. encoding. 10 5

Load-Store format Need for Opcode (6 bits) Register destination (for Load) and source (for Store) : rt Base register: rs Offset (immed field) Example Lw $14,8($sp) #$14 loaded from top of #stack + 8 35 29 14 8 1/13/99 CSE378 Instr. encoding. 11 Loading small constants in a register If the constant is small (i.e., can be encoded in 16 bits) use the immediate format with Li (Load immediate) Li $14,8 #$14 = 8 But, there is no opcode for Li! Li is a pseudoinstruction It s there to help you SPIM will recognize it and transform it into Ori Ori $14,$0,8 #$14 = $0+8 Note that the loading of a constant is done with signextension when using Addi 1/13/99 CSE378 Instr. encoding. 12 6

Loading large constants in a register If the constant does not fit in 16 bits (e.g., an address) Use a two-step process Lui (load upper immediate) to load the upper 16 bits; it will zero out automatically the lower 16 bits Use Addi for the lower 16 bits (but not Li, why?) Example: Load the constant 0x1B234567 in register $t0 Lui $t0,0x1b23 #note the use of hex constants Addi $t0,$t0,0x4567 1/13/99 CSE378 Instr. encoding. 13 How to address memory in assembly language Problem: how do I put the base address in the right register and how do I compute the offset Method 1 (most recommended). Let the assembler do it!.data #define data section xyz:.word 1 #reserve room for 1 word at address xyz.. #more data.text #define program section.. # some lines of code lw $5, xyz # load contents of word at add. xyz in $5 In fact the assembler generates: Lw $5, offset ($gp) #$gp is register 28 1/13/99 CSE378 Instr. encoding. 14 7

Generating addresses Method 2. Use the pseudo-instruction La (Load address) La $6,xyz #$6 contains address of xyz Lw $5,0($6) #$5 contains the contents of xyz La is in fact Lui followed by Addi This method can be useful to traverse an array after loading the base address in a register Method 3 If you know the address (i.e. a constant) use Li or Lui + Addi 1/13/99 CSE378 Instr. encoding. 15 8