MIPS PROJECT INSTRUCTION SET and FORMAT

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

COMP MIPS instructions 2 Feb. 8, f = g + h i;

The MIPS Instruction Set Architecture

Programmable Machines

Programmable Machines

Computer Architecture. The Language of the Machine

CS3350B Computer Architecture MIPS Instruction Representation

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

MIPS Instruction Reference

Computer Architecture

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

bits 5..0 the sub-function of opcode 0, 32 for the add instruction

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Review of instruction set architectures

Reduced Instruction Set Computer (RISC)

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

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

Assembly Programming

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Topic Notes: MIPS Instruction Set Architecture

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

Chapter 2A Instructions: Language of the Computer

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

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Reduced Instruction Set Computer (RISC)

CS 61c: Great Ideas in Computer Architecture

Examples of branch instructions

ECE 486/586. Computer Architecture. Lecture # 7

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

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

ECE 30 Introduction to Computer Engineering

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Computer Architecture

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

Flow of Control -- Conditional branch instructions

Mips Code Examples Peter Rounce

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

CS61C : Machine Structures

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

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

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

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

MIPS Memory Access Instructions

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

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

Unsigned Binary Integers

Unsigned Binary Integers

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

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

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

Concocting an Instruction Set

CS3350B Computer Architecture MIPS Introduction

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

MIPS Coding Continued

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

Concocting an Instruction Set

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

RISC-V Assembly and Binary Notation

Q1: /30 Q2: /25 Q3: /45. Total: /100

Lecture 4: MIPS Instruction Set

Lecture 9: Disassembly

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

Midterm. CS64 Spring Midterm Exam

F. Appendix 6 MIPS Instruction Reference

CS222: MIPS Instruction Set

Instructions: Language of the Computer

Instructions: Language of the Computer

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

ece4750-tinyrv-isa.txt

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

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

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

CS61c MIDTERM EXAM: 3/17/99

Review: ISA. Review: Compiling Applications. Computer Architecture ELEC3441. Instruction Set Architecture (1) Computer Architecture: HW/SW Interface

MIPS%Assembly% E155%

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

EE108B Lecture 3. MIPS Assembly Language II

Review of the Machine Cycle

Concocting an Instruction Set

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

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

Computer Architecture. MIPS Instruction Set Architecture

CS3350B Computer Architecture

MIPS Instruction Set

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

CS61C : Machine Structures

Course Administration

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

MIPS Reference Guide

UCB CS61C : Machine Structures

Chapter 2. Instructions:

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

Concocting an Instruction Set

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

Thomas Polzer Institut für Technische Informatik

Lectures 3-4: MIPS instructions

CS 4200/5200 Computer Architecture I

Transcription:

ECE 312: Semester Project MIPS PROJECT INSTRUCTION SET FORMAT This is a description of the required MIPS instruction set, their meanings, syntax, semantics, bit encodings. The syntax given for each instruction refers to the assembly language syntax supported by the MIPS assembler. Hyphens in the encoding indicate "don't care" bits which are not considered when an instruction is being decoded. MIPS Assembler Instructions Instruction Format The MIPS R2000/R3000 ISA has fixed-width 32 bit instructions. Fixed-width instructions are common for RISC processors because they make it easy to fetch instructions without having to decode. These instructions must be stored at word-aligned addresses (i.e., addresses divisible by 4). The MIPS ISA instructions fall into three categories: R-type, I-type, J-type. Not all ISAs divide their instructions this neatly. This is one reason to study MIPS as a first assembly language. The format is simple. R-type R-type instructions refer to register type instructions. Of the three formats, the R-type is the most complex. This is the format of the R-type instruction, when it is encoded in machine code. BB31-26 BB25-21 BB20-16 BB15-11 BB10-6 BB5-0 opcode register s register t register d shift amount function The prototypical R-type instruction is: add $rd, $rs, $rt where $rd refers to some register d (d is shown as a variable, however, to use the instruction, you must put a number between 0 31, inclusive for d). $rs, $rt are also registers. The semantics of the instruction are; R[d] = R[s] + R[t] where the addition is signed addition. You will notice that the order of the registers in the instruction is the destination register ($rd), followed by the two source registers ($rs $rt). However, the actual binary format (shown in the table above) stores the two source registers first, then the destination register. Thus, how the assembly language programmer uses the instruction, how the instruction is stored in binary, do not always have to match.

Let's explain each of the fields of the R-type instruction. opcode (B 31-26 ) Opcode is short for "operation code". The opcode is a binary encoding for the instruction. Opcodes are seen in all ISAs. In MIPS, there is an opcode for add. The opcode in MIPS ISA is only 6 bits. Ordinarily, this means there are only 64 instructions. Even for a RISC ISA, which typically has few instructions, 64 is quite small. For R-type instructions, an additional 6 bits are used (B 5-0 ) called the function. Thus, the 6 bits of the opcode the 6 bits of the function specify the kind of instruction for R-type instructions. rd (B 25-21 ) This is the destination register. The destination register is the register where the result of the operation is stored. rs (B 20-16 ) This is the first source register. The source register is the register that holds one of the arguments of the operation. rt (B 15-11 ) This is the second source register. shift amount (B 10-6 ) The amount of bits to shift. Used in shift instructions. function (B 5-0 ) An additional 6 bits used to specify the operation, in addition to the opcode. I-type instructions I-type is short for "immediate type". The format of an I-type instuction looks like: BB31-26 BB25-21 BB20-16 BB15-0 opcode register s register t immediate The prototypical I-type instruction looks like: add $rt, $rs, immed In this case, $rt is the destination register, $rs is the only source register. It is unusual that $rd is not used, that $rd does not appear in bit positions BB25-21 for both R-type I-type instructions. Presumably, the designers of the MIPS ISA had their reasons for not making the destination register at a particular location for R-type I-type. The semantics of the addi instruction are;

R[t] = R[s] + (IR 15 ) 16 IR 15-0 where IR refers to the instruction register, the register where the current instruction is stored. (IR 15 ) 16 means that bit BB15 of the instruction register (which is the sign bit of the immediate value) is repeated 16 times. This is then followed by IR 15-0, which is the 16 bits of the immediate value. Basically, the semantics says to sign-extend the immediate value to 32 bits, add it (using signed addition) to register R[s], store the result in register $rt. J-type instructions J-type is short for "jump type". The format of an J-type instuction looks like: BB31-26 opcode BB25-0 target The prototypical I-type instruction looks like: j target The semantics of the j instruction (j means jump) are: PC <- PC 31-28 IR 25-0 00 where PC is the program counter, which stores the current address of the instruction being executed. You update the PC by using the upper 4 bits of the program counter, followed by the 26 bits of the target (which is the lower 26 bits of the instruction register), followed by two 0's, which creates a 32 bit address. The jump instruction will be explained in more detail in a future set of notes. Why Five Bits? If you look at the R-type I-type instructions, you will see 5 bits reserved for each register. You might wonder why. MIPS supports 32 integer registers. To specify each register, the register are identified with a number from 0 to 31. It takes log 2 32 = 5 bits to specify one of 32 registers. If MIPS has 64 register, you would need 6 bits to specify the register. The register number is specified using unsigned binary. Thus, 00000 refers to $r0 11111 refers to register $r31. Why Study Instruction Formats You might wonder why it's important to study instruction formats. They seem to be arbitrarily constructed. Yet, they aren't. For example, it's quite useful to have the opcode be the same size the same location. It's useful to know the exact bits used for the immediate value. This makes decoding much quicker, the hardware to hle instruction decoding that much simpler. Furthermore, you begin to realize what information the instructions store. For example, it's not all that obvious that immediate values are stored as part of the instruction for I-type instructions. If you know that, for example, addi does signed addition, then you can also conclude that the immediate value is represented in 2C. Also, to add the immediate value to a 32-bit register value would mean sign-extending the immediate value to 32 bits.

However, not all I-type instructions encode the 16 bit immediate in 2C. For example, addiu (add immediate unsigned) interprets the 16 bits as UB. It zero-extends the immediate then adds it to the value stored in a 32 bit register. Three Oper Instructions Also, notice that the R-type instructions use three opers (i.e., arguments). In earlier, pre- RISC ISAs, memory was expensive, so ISA designers tried to minimize the number of bits used in an instruction. This meant that there were often two, one, or no opers. How did they manage that? Here's an example of an instruction cisc_add $r1, $r2 # R[1] = R[1] + R[2] One way to reduce the total number of opers is to make one oper both a source a destination register. Another approach is to use an implicit register. acc_add $r2 # Acc = Acc + R[2] For example, there may be a special register called the accumulator. This register is not mentioned explicitly in the instruction. Instead, it is implied by the opcode. Early personal computers such as the Apple 2, used ISAs with 1 or 2 registers, those registers were often part of most instructions, thus they didn't have to be specified. With memory becoming cheaper, memory access becoming cheaper, it's become easier to devote more bits to an instruction, to specify three opers instead of two. This makes it more convenient for the assembly language programmer. In Summary MIPS instructions fall into three categories: R-type, I-type, J-type. You should know how the bits are laid out (i.e., what the 6 parts of the R-type instruction are, how many bits in each of the 6 parts). However, it's unnecessary to memorize opcodes. Instruction Set: Category Instruction Example Meaning Comments Arithmetic add subtract add immediate add unsigned add sub addi addu $1 = $2 + $3 $1 = $2 - $3 $1 = $2 + 100 $1 = $2 + $3 3 opers; exception 3 opers; exception + constant; exception 3 opers; exception subtract unsigned subi $1 = $2 - $3 3 opers; exception

Logical Data transfer Conditional branch Unconditional jump add immediate unsigned Move from coprocessor register addi mfc0 $1,$epc $1 = $2 + 100 $1 = $epc $1 = $2 & $3 or or $1 = $2 $3 immediate or immediate or $1 = $2 & 100 $1 = $2 100 + constant; exception Used to get of Exception PC 3 register opers; Logical AND 3 register opers; Logical OR Logical AND register, constant Logical OR register, constant shift left logical sll $1,$2,10 $1 = $2 << 10 Shift left by constant shift right logical srl $1,$2,10 $1 = $2 >> 10 Shift right by constant load word store word load upper immediate lw $1,(100)$2 sw $1,(100)$2 beq branch on equal branch on not equal bne set on less than immediate unsigned immediate unsigned $1 = Memory[$2+100] Memory[$2+100] = $1 Data from memory to register Data from memory to register lui $1,100 $1 = 100 * 2 16 Load constant in upper 16bits slt slti sltu sltiu if ($1 == $2) go to PC+4+100 if ($1!= $2) go to PC+4+100 if ($2 < $3) $1 = 1; else $1 = 0 if ($2 < 100) $1 = 1; else $1 = 0 if ($2 < $3) $1 = 1; else $1 = 0 if ($2 < 100) $1 = 1; else $1 = 0 Equal test; PC relative branch Not equal test; PC relative Compare less than; 2`s complement Compare < constant; 2`s complement Compare less than; natural number Compare constant; natural number jump j 10000 goto 10000 Jump to target address jump register j $31 goto $31 For switch, procedure return jump link jal 10000 $31 = PC + 4;go to 10000 For procedure call