ECE260: Fundamentals of Computer Engineering

Similar documents
ECE260: Fundamentals of Computer Engineering

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

Unsigned Binary Integers

Unsigned Binary Integers

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

Reduced Instruction Set Computer (RISC)

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

MIPS Instruction Set

Reduced Instruction Set Computer (RISC)

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

ECE260: Fundamentals of Computer Engineering

MIPS%Assembly% E155%

ECE 15B Computer Organization Spring 2010

ECE 154A Introduction to. Fall 2012

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

CS3350B Computer Architecture MIPS Instruction Representation

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

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

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

Computer Architecture

M2 Instruction Set Architecture

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

Concocting an Instruction Set

The MIPS Instruction Set Architecture

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: 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)

Arithmetic for Computers

F. Appendix 6 MIPS Instruction Reference

MIPS Instruction Reference

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

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

Chapter 2A Instructions: Language of the Computer

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

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

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

Computer Architecture. Lecture 2 : Instructions

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

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

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

EE 109 Unit 8 MIPS Instruction Set

CSEE 3827: Fundamentals of Computer Systems

Concocting an Instruction Set

Topic Notes: MIPS Instruction Set Architecture

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

Concocting an Instruction Set

Computer Architecture. The Language of the Machine

Examples of branch instructions

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

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

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

Five classic components

Review: MIPS Organization

Lecture 4: MIPS Instruction Set

Flow of Control -- Conditional branch instructions

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

Concocting an Instruction Set

EE108B Lecture 3. MIPS Assembly Language II

TSK3000A - Generic Instructions

MIPS Reference Guide

Chapter Two MIPS Arithmetic

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

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

Computer Architecture. MIPS Instruction Set Architecture

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

CS61C : Machine Structures

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Number Systems and Their Representations

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

Assembly Programming

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

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

Instruction encoding. MIPS Instruction encoding

UCB CS61C : Machine Structures

ECE331: Hardware Organization and Design

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

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

CS 61c: Great Ideas in Computer Architecture

CPS311 - COMPUTER ORGANIZATION. A bit of history

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

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

MIPS Instruction Format

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

INSTRUCTION SET COMPARISONS

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

CS 4200/5200 Computer Architecture I

Mips Code Examples Peter Rounce

Computer Science 61C Spring Friedland and Weaver. Instruction Encoding

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

Chapter 4. The Processor

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 R-Type ALU instruction rs = 17 1 st source reg $s1 rt = 18 2 nd source reg $s2 rd = 8 destination reg $t0 shamt = 0 shift amount unused here funct = 32 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 An example addi instruction: op = 8 addi instruction rs = 11 source reg $t3 rt = 9 destination reg $t1 constant = 3 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- extended prior to summing with rs. addi $t1, $t3, -3 Use addiu for unsigned sum. 8

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 9

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 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. 10

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 11

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 12

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 13

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 14