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

Similar documents
M2 Instruction Set Architecture

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

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

Instruction encoding. MIPS Instruction encoding

Reduced Instruction Set Computer (RISC)

The MIPS Instruction Set Architecture

3. Instruction Set Architecture The MIPS architecture

Computer Architecture. The Language of the Machine

Laboratory Exercise 6 Pipelined Processors 0.0

Course Administration

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

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

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

CSSE 232 Computer Architecture I. I/O and Addressing

Reduced Instruction Set Computer (RISC)

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

Instructions: Language of the Computer

MIPS Instruction Format

MIPS%Assembly% E155%

EE108B Lecture 3. MIPS Assembly Language II

MIPS Reference Guide

Computer Architecture

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

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

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CS 4200/5200 Computer Architecture I

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

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

CS3350B Computer Architecture MIPS Instruction Representation

EE 109 Unit 8 MIPS Instruction Set

2.1 DOWNLOAD AND INSTALL MARS

Computer Architecture. MIPS Instruction Set Architecture

TSK3000A - Generic Instructions

MIPS Instruction Set

CPS311 - COMPUTER ORGANIZATION. A bit of history

MIPS (SPIM) Assembler Syntax

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

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

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

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

CS 351 Exam 2 Mon. 11/2/2015

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

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

Chapter Two MIPS Arithmetic

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

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

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

ECE 154A Introduction to. Fall 2012

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

MIPS Instruction Reference

A Model RISC Processor. DLX Architecture

Mips Code Examples Peter Rounce

Exam in Computer Engineering

CS3350B Computer Architecture

Computer Architecture Experiment

MIPS Instruction Set Architecture (2)

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

ECE260: Fundamentals of Computer Engineering

Design for a simplified DLX (SDLX) processor Rajat Moona

MIPS Assembly Language. Today s Lecture

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

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

F. Appendix 6 MIPS Instruction Reference

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

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

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

Lecture 2: RISC V Instruction Set Architecture. Housekeeping

CS3350B Computer Architecture MIPS Introduction

ECE260: Fundamentals of Computer Engineering

Computer Organization MIPS ISA

EE 109 Unit 10 MIPS Instruction Set. MIPS Processor and Bus Interface. Instruction Set Architecture (ISA) MIPS INSTRUCTION OVERVIEW

Lecture 2: RISC V Instruction Set Architecture. James C. Hoe Department of ECE Carnegie Mellon University

Lecture 3: Single Cycle Microarchitecture. James C. Hoe Department of ECE Carnegie Mellon University

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

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

CENG3420 Lecture 03 Review

EN2910A: Advanced Computer Architecture Topic 02: Review of classical concepts

Computer Organization Lab #3.

Programmable Machines

MIPS Assembly Programming

CS 61c: Great Ideas in Computer Architecture

Programmable Machines

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

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

Unsigned Binary Integers

Unsigned Binary Integers

COMPUTER ORGANIZATION AND DESIGN

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

EECS Computer Organization Fall Based on slides by the author and prof. Mary Jane Irwin of PSU.

Computer Systems and Architecture

INSTRUCTION SET COMPARISONS

CSCI 402: Computer Architectures

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

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

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

Project Part A: Single Cycle Processor

Transcription:

ICS 233 Computer Architecture & Assembly Language MIPS PROCESSOR INSTRUCTION SET 1 ICS 233 Computer Architecture & Assembly Language Lecture 7 2 1

Lecture Outline MIPS Instruction I-Type Format MIPS I-type ALU Instructions MIPS I-type Data Transfer Instructions (Load & Store Instructions) 3 I-Type Format Constants are used quite frequently in programs The R-type shift instructions have a 5-bit shift amount constant What about other instructions that need a constant? I-Type: Instructions with Immediate Operands Op 6 Rs 5 Rt 5 immediate 16 16-bit immediate constant is specified immediately in the instruction Rs is the source register number Rt is now the destination register number (for R-type it was Rd) Examples of I-Type ALU Instructions: Add immediate: addi $s1, $s2, 5 # $s1 = $s2 + 5 OR immediate: ori $s1, $s2, 5 # $s1 = $s2 5 4 2

I-Type ALU Instructions Instruction Meaning I-Type Format addi $s1, $s2, 10 $s1 = $s2 + 10 op = 0x8 rs = $s2 rt = $s1 imm 16 = 10 addiu $s1, $s2, 10 $s1 = $s2 + 10 op = 0x9 rs = $s2 rt = $s1 imm 16 = 10 andi $s1, $s2, 10 $s1 = $s2 & 10 op = 0xc rs = $s2 rt = $s1 imm 16 = 10 ori $s1, $s2, 10 $s1 = $s2 10 op = 0xd rs = $s2 rt = $s1 imm 16 = 10 xori $s1, $s2, 10 $s1 = $s2 ^ 10 op = 0xe rs = $s2 rt = $s1 imm 16 = 10 lui $s1, 10 $s1 = 10 << 16 op = 0xf 0 rt = $s1 imm 16 = 10 addi: overflow causes an arithmetic exception In case of overflow, result is not written to destination register addiu: same operation as addi but overflow is ignored Immediate constant for addi and addiu is signed No need for subi or subiu instructions Immediate constant for andi, ori, xori is unsigned 5 MIPS - Arithmetic Instructions addi (add immediate signed ) addi rd, rs, const rd rs + const ; const is a 16-bit constant value ;overflow detected addi $s1, $s2, 100 ; $s1 $s2 + 100 addiu (add immediate unsigned) addiu rd, rs, const rd rs + const ; const is a 16-bit constant value ;overflow not detected addiu $s1, $s2, 100 ; $s1 $s2 + 100 6 3

MIPS - Logical Instructions andi (logical and immediate) andi rd, rs, const ; const is a 16-bit constant rd rs & const andi $s1, $s2, 100 ; $s1 $s2 & 100 7 MIPS - Logical Instructions ori (logical or immediate) ori rd, rs, const ; where rs, rd are registers, ; const is a 16-bit constant rd rs const ori $s1, $s2, 100 ; $s1 $s2 I 100 8 4

MIPS - Logical Instructions xori (logical Exclusive-or immediate) xori rd, rs, const ; const is a 16-bit value rd rs const xori $s1, $s2, 100 ; $s1 $s2 + 100 9 MIPS Data Transfer Instructions lui (Load upper immediate) lui rd, const ;where rd is a register, rd const*2 16 ;const is a 16-bit number lui $s1, 100 ; $s1 100 * 2 16 ; load constant in upper 16 bits of register 10 5

32-bit Constants I-Type instructions can have only 16-bit constants Op 6 Rs 5 Rt 5 immediate 16 What if we want to load a 32-bit constant into a register? Can t have a 32-bit constant in I-Type instructions We have already fixed the sizes of all instructions to 32 bits Solution: use two instructions instead of one Suppose we want: $s1=0xac5165d9 (32-bit constant) lui: load upper immediate lui $s1,0xac51 $s1($17) load upper 16 bits 0xAC51 clear lower 16 bits 0x0000 ori $s1,$s1,0x65d9 $s1($17) 0xAC51 0x65D9 Examples: I-Type ALU Instructions Examples: assume A, B, C are allocated $s0, $s1, $s2 A = B+5; C = B 1; addiu $s0,$s1,5 addiu $s2,$s1,-1 op=001001 rs=$s1=10001 rt=$s2=10010 imm = -1 = 1111111111111111 A = B&0xf; C = B 0xf; C = 5; A = B; andi ori ori ori $s0,$s1,0xf $s2,$s1,0xf $s2,$zero,5 $s0,$s1,0 No need for subi, because addi has signed immediate Register 0 ($zero) has always the value 0 6

Load and Store Instructions Instructions that transfer data between memory & registers Programs include variables such as arrays and objects Such variables are stored in memory Load Instruction: Transfers data from memory to a register Registers load store Memory Store Instruction: Transfers data from a register to memory Memory address must be specified by load and store 13 Load and Store Word Load Word Instruction (Word = 4 bytes in MIPS) lw Rt, imm 16 (Rs) # Rt = MEMORY[Rs+imm 16 ] Store Word Instruction sw Rt, imm 16 (Rs) # MEMORY[Rs+imm 16 ] = Rt Base or Displacement addressing is used Memory Address = Rs (base) + Immediate 16 (displacement) Immediate 16 is sign-extended to have a signed displacement Base or Displacement Addressing Op 6 Rs 5 Rt 5 immediate 16 Base address + Memory Word 14 7

Example on Load & Store Translate A[1] = A[2] + 5 (A is an array of words) Assume that address of array A is stored in register $s0 lw $s1, 8($s0) # $s1 = A[2] addiu $s2, $s1, 5 # $s2 = A[2] + 5 sw $s2, 4($s0) # A[1] = $s2 Index of a[2] and a[1] should be multiplied by 4. Why? Registers Memory...... $s0 = $16 $s1 = $17 $s2 = $18 address of A value of A[2] A[2] + 5... lw sw A[3] A[2] A[1] A[0] A+12 A+8 A+4 A... 15 Load and Store Byte and Halfword The MIPS processor supports the following data formats: Byte = 8 bits, Halfword = 16 bits, Word = 32 bits Load & store instructions for bytes and halfwords lb = load byte, lbu = load byte unsigned, sb = store byte lh = load half, lhu = load half unsigned, sh = store halfword Load expands a memory data to fit into a 32-bit register Store reduces a 32-bit register to fit in memory 32-bit Register s sign extend ss 0 zero extend 0 s sign extend s s h 0 zero extend 0 hu b bu 16 8

Load and Store Instructions Instruction lb rt, imm 16 (rs) lh rt, imm 16 (rs) lw rt, imm 16 (rs) lbu rt, imm 16 (rs) lhu rt, imm 16 (rs) sb rt, imm 16 (rs) sh rt, imm 16 (rs) sw rt, imm 16 (rs) Meaning rt = MEM[rs+imm 16 ] rt = MEM[rs+imm 16 ] rt = MEM[rs+imm 16 ] rt = MEM[rs+imm 16 ] rt = MEM[rs+imm 16 ] MEM[rs+imm 16 ] = rt MEM[rs+imm 16 ] = rt MEM[rs+imm 16 ] = rt 0x20 0x21 0x23 0x24 0x25 0x28 0x29 0x2b I-Type Format Base or Displacement Addressing is used Memory Address = Rs (base) + Immediate 16 (displacement) Two variations on base addressing If Rs = $zero = 0 then Address = Immediate 16 (absolute) If Immediate 16 = 0 then Address = Rs (register indirect) 17 MIPS Data Transfer Instructions lw (Load word) lw rd, const(rs) lw rd, addr rd Memory[rs + const] ;const is a 16-bit displacement ; where addr is the label of the memory location to be accessed ; load word from memory to register lw $s1, 100($s2) lw $s1, NUM1 ; $s1 Memory[$s2+100] ; load register $s1 with a word from memory location NUM1 18 9

MIPS Data Transfer Instructions lh (Load halfword with sign extension) lh rd, const(rs) ;const is a 16-bit displacement lh rd, addr ; where addr is the label of the memory location to be accessed rd Memory[rs + const] ; load halfword from memory to register lh $s1, 100($s2) ; $s1 Memory[$s2+100] lh $s1, NUM1 ; load register $s1 with a half-word from memory location NUM1 lhu (Load halfword unsigned without sign extension) lhu rd, const(rs) ;const is a 16-bit displacement lhu rd, addr ; where addr is the label of the memory location to be accessed rd Memory[rs + const] ; load halfword from memory to register lhu $s1, 100($s2) ; $s1 Memory[$s2+100] lhu $s1, NUM1 ; load register $s1 with a half-word from memory location NUM1 19 MIPS Data Transfer Instructions lb (Load byte with sign extension) lb rd, const(rs) ;const is a 16-bit displacement lb rd, addr ; where addr is the label of the memory location to be accessed rd Memory[rs + const] ; load byte from memory to register lb $s1, 100($s2) ; $s1 Memory[$s2+100] lb $s1, NUM1 ; load register $s1 with a byte from memory location NUM1 lbu (Load byte unsigned without sign extension) lbu rd, const(rs) lbu rd, addr rd Memory[rs + const] lbu $s1, 100($s2) lbu $s1, NUM1 ;const is a 16-bit displacement ; where addr is the label of the memory location to be accessed ; load unsigned byte from memory to register ; $s1 Memory[$s2+100] ; load register $s1 with a byte from memory location NUM1 20 10