ECE260: Fundamentals of Computer Engineering

Similar documents
ECE260: Fundamentals of Computer Engineering

Unsigned Binary Integers

Unsigned Binary Integers

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

CSCI 402: Computer Architectures

Lecture Topics. Announcements. Today: The MIPS ISA (P&H ) Next: continued. Milestone #1 (due 1/26) Milestone #2 (due 2/2)

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

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

ECE232: Hardware Organization and Design

Instructions: Language of the Computer

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Reduced Instruction Set Computer (RISC)

MIPS Instruction Set

Reduced Instruction Set Computer (RISC)

ECE260: Fundamentals of Computer Engineering

MIPS%Assembly% E155%

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

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

ECE 154A Introduction to. Fall 2012

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

ECE 15B Computer Organization Spring 2010

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

CS3350B Computer Architecture MIPS Instruction Representation

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

Computer Architecture

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

M2 Instruction Set Architecture

Concocting an Instruction Set

The MIPS Instruction Set Architecture

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: The MIPS ISA (P&H ) Consulting hours. Milestone #1 (due 1/26)

F. Appendix 6 MIPS Instruction Reference

Arithmetic for Computers

MIPS Instruction Reference

Chapter 2A Instructions: Language of the Computer

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

Midterm. Sticker winners: if you got >= 50 / 67

Examples of branch instructions

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

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

Computer Architecture. Lecture 2 : Instructions

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

CS61C Machine Structures. Lecture 13 - MIPS Instruction Representation I. 9/26/2007 John Wawrzynek. www-inst.eecs.berkeley.

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

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

Flow of Control -- Conditional branch instructions

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

CSEE 3827: Fundamentals of Computer Systems

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

Topic Notes: MIPS Instruction Set Architecture

EE 109 Unit 8 MIPS Instruction Set

Concocting an Instruction Set

Review: MIPS Organization

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

MACHINE LANGUAGE. To work with the machine, we need a translator.

Concocting an Instruction Set

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

Computer Architecture. The Language of the Machine

Lecture 4: MIPS Instruction Set

Five classic components

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

CS61C : Machine Structures

Number Systems and Their Representations

Concocting an Instruction Set

EE108B Lecture 3. MIPS Assembly Language II

TSK3000A - Generic Instructions

UCB CS61C : Machine Structures

MIPS Reference Guide

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

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

Computer Architecture. MIPS Instruction Set Architecture

Chapter Two MIPS Arithmetic

Review 1/2 MIPS assembly language instructions mapped to numbers in 3 formats. CS61C Negative Numbers and Logical Operations R I J.

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

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

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

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

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Assembly Programming

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

Instruction encoding. MIPS Instruction encoding

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

CS 61c: Great Ideas in Computer Architecture

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

ECE331: Hardware Organization and Design

CPS311 - COMPUTER ORGANIZATION. A bit of history

Chapter 4. The Processor

MIPS Instruction Format

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

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 Structure. Bing-Yu Chen National Taiwan University

CS 4200/5200 Computer Architecture I

INSTRUCTION SET COMPARISONS

Mips Code Examples Peter Rounce

MIPS Instruction Set Architecture (2)

Transcription:

MIPS Instruction Set James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy

MIPS Registers MIPS architecture has a 32 32-bit register file (e.g. it has 32 32-bit registers) Registers are numbered 0 to 31 Registers can be referenced in assembly code using various names Register Number Register Name Use 0 $zero Constant value 0 1-7 Coming soon Coming soon 8-15 $t0 - $t7 Temporary values 16-23 $s0 - $s7 Saved temporary values 24-25 $t8 - $t9 Temporary values 26-31 Coming soon Coming soon 2

Representing Instructions All instructions are encoded in binary Binary values represent type of instruction, source and destination registers, etc. Sequence of binary instructions is referred to as machine code Machine code is the output of an assembler Contents of executable application files is machine code Loaded into TEXT section of memory when application runs Interpreted by CPU as program executes 3

MIPS Instruction Formats MIPS instructions are encoded as 32-bit words Three basic MIPS instruction formats MIPS instructions includes multiple fields : A 6-bit operation or OPCODE Specifies which operation to execute (fewer than 64) Up to three 5-bit OPERAND fields Each a register (one of 32) as source/destination May contain embedded constants or immediate values 5-bits, 16-bits, or 26-bits long 3 register operands (2 source, 1 dest.) R-Type opcode rs rt rd shamt funct 6-bits 5-bits 5-bits 5-bits 5-bits 6-bits 2 register operands, 16-bit constant I-Type opcode rs rt 16-bit constant/offset 6-bits 5-bits 5-bits 16-bits No register operands, 26-bit address constant J-Type opcode 26-bit address constant 6-bits 26-bits Can be treated as signed or unsigned 4

MIPS R-Type Instructions Used for operations that require two source operands and shift operations add, addu, sub, subu, div, divu, mult, multu, and, or, nor, xor, etc. sll, srl, sra Instruction fields op: operation code (opcode) 3 register operands (2 source, 1 dest.) R-Type opcode rs rt rd shamt funct 6-bits 5-bits 5-bits 5-bits 5-bits 6-bits rs: first source register number rt: second source register number rd: destination register number shamt: shift amount funct: function code (extends opcode) 5

MIPS R-Type Instruction Example An example add instruction: op = 0 ten R-Type ALU instruction rs = 17 ten 1 st source reg $s1 rt = 18 ten 2 nd source reg $s2 rd = 8 ten destination reg $t0 shamt = 0 ten shift amount unused here funct = 32 ten in conjunction with opcode, add R-Type 0 0 0 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 = 0x02324020 opcode rs rt rd shamt funct 6-bits 5-bits 5-bits 5-bits 5-bits 6-bits add $8, $17, $18 NOTE: the ordering of registers is different between the machine add $t0, $s1, $s2 code and the assembly 6

MIPS I-Type Instructions Used for immediate arithmetic, load/store, comparisons, branching instructions addi, addiu, andi, ori, etc. lw, sw, etc. Instruction fields op: operation code (opcode) 2 register operands, 16-bit constant/offset I-Type opcode rs rt 16-bit constant/offset 6-bits 5-bits 5-bits 16-bits rs: base address for load/store operations rt: destination or source register number 16-bit constant/offset: 2 15 to +2 15 1 Constant for instructions that use immediate values Offset for load and store operations (added to base address) Offset for branching operations 7

MIPS I-Type Instruction Example (immediate) An example addi instruction: op = 8 ten addi instruction rs = 11 ten source reg $t3 rt = 9 ten destination reg $t1 constant = 3 ten value to add to rs I-Type 0 0 1 0 0 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 = 0x2169FFFD opcode rs rt 16-bit constant/offset 6-bits 5-bits 5-bits 16-bits addi $9, $11, -3 NOTE: the 16-bit constant is sign- addi $t1, $t3, -3 extended prior to summing with rs. 8

MIPS I-Type Instruction Example (load) An example lw instruction: op = 35 ten lw instruction rs = 15 ten base reg $t7 rt = 23 ten destination reg $s7 constant = 4 ten offset to add to base register rs I-Type 1 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 = 0x8DF70004 opcode rs rt 16-bit constant/offset 6-bits 5-bits 5-bits 16-bits lw $23, 4($15) NOTE: the 16-bit constant is sign- lw $s7, 4($t7) extended prior to summing with rs. 9

MIPS I-Type Instruction Example (store) An example sw instruction: op = 43 ten sw instruction rs = 8 ten base reg $t7 rt = 21 ten source reg $s7 constant = 12 ten offset to add to base register rs I-Type 1 0 1 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 = 0xAD15000C opcode rs rt 16-bit constant/offset 6-bits 5-bits 5-bits 16-bits sw $21, 12($8) NOTE: the 16-bit constant is sign- sw $s5, 12($t0) extended prior to summing with rs. 10

Logical Operations Instructions for bitwise manipulation Useful for extracting and inserting groups of bits in a word Operation C / C++ MIPS Shift Left << sll Shift Right >> srl, sra Bitwise AND & and, andi Bitwise OR or, ori Bitwise XOR ^ xor Bitwise NOT ~ nor int x = 3; int y = 4; int z; z = x << 1; // z is now 6 z = y >> 1; // z is now 2 z = x & y; // z is now 0 z = x y; // z is now 7 z = x ^ y; // z is now 7 z = ~x; // z is now 0xfffffffc either -4 or 4,294,967,292 11

Shift Operations Uses R-Type instruction shamt field how many positions to shift Shift left logical 3 register operands (2 source, 1 dest.) R-Type opcode rs rt rd shamt funct 6-bits 5-bits 5-bits 5-bits 5-bits 6-bits Shift left and fill with 0 bits sll by i bits multiplies by 2 i Shift right logical before Shift right and fill with 0 bits srl by i bits divides by 2 i (unsigned only) Shift right arithmetic Shift right and fill with copy of MSB Shift Left Logical: The empty position in the least significant bit is filled with a zero. Shift Right Arithmetic: The empty position in the most significant bit is filled with a copy of the original MSB. after 12

AND Operations Uses R-Type instruction (opcode = 0x00, funct = 0x24) Useful to mask bits in a word Select some bits, clear others to 0 and $t0, $t1, $t2 register $t1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 register $t2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 perform AND operation result of AND stored in register $t0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 13

OR Operations Uses R-Type instruction (opcode = 0x00, funct = 0x25) Useful to include bits in a word Set some bits to 1, leave others unchanged or $t0, $t1, $t2 register $t1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 register $t2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 perform OR operation result of OR stored in register $t0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 14

XOR Operations Uses R-Type instruction (opcode = 0x00, funct = 0x26) Useful to find bits that differ between words Set output bit to 1 if input bits differ, others 0 xor $t0, $t1, $t2 register $t1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 register $t2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 perform XOR operation result of XOR stored in register $t0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 15

NOT Operations MIPS has no NOT instruction Instead, uses a NOR instruction (R-Type) a NOR b == NOT(a OR b) // to get a NOT, just set b=0 nor $t0, $t1, $zero # negates $t1, stores result in $t0 Useful to invert bits in a word Changes 0 s to 1 s, and 1 s to 0 s register $t1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 perform NOR operation result of NOR stored in register $t0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 16