# Mips Code Examples Peter Rounce

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Mips Code Examples Peter Rounce

2 Some C Examples Assignment : int j = 10 ; // space must be allocated to variable j Possibility 1: j is stored in a register, i.e. register \$2 then the MIPS assembler for this is :- addi \$2, \$0, 10 : \$2 <- \$0 + sign-extend[10] Possibility 2: j is stored in memory, i.e. memory 0x then the MIPS assembler for this might be:- lui \$1, 0x1234 : \$1 0x ori \$1, \$1, 0x5678 : \$1 0x addi \$8, \$0, 10 : \$8 \$0 + sign-extend[10] Get address in \$1 Get 10 in \$8 sw \$8, 0(\$1) : Mem[\$1 + 0] \$8 Store 100x

3 Program to calculate Absolute value of difference between 2 input numbers: A - B (demonstrates if) Program reads A from 4 bytes of memory starting at address Program reads B from 4 bytes of memory starting at address Program writes A-B to 4 bytes of memory starting at address Assembler lui \$10, 0x1234 ori \$10, \$10, 0x5670 lw \$4, 0(\$10) lw \$5, 4(\$10) sub \$12, \$5, \$4 bgez \$12,+1 sub \$12, \$4, \$5 sw \$12, 8(\$10) # Comment # put address of A into register \$10 # read A from memory into register \$4 # read B from memory into register \$5 (A address+4) # subtract A from B => B-A into register \$12 # branch if B-A is positive to sw instruction # subtract B from A => A-B into register \$12 # store register \$12 value, A-B, into memory N.B. program uses displacement to access other locations from address of memory storing value of A

4 code in \$4: in \$5: R s bits in \$6: in \$6: Given the binary for an instruction e.g.: What code would you write to get the r s register number into a register on its own, and into the low bits of this register? Shift right logical What is wanted. R s bits and Code: assume code in \$4 // get masking value in \$5 lui \$5, 0x03e0 and \$6, \$5, \$4 // masked value in \$6 // so shift \$6 right srl \$6, \$6, 21

5 Change r s field in instruction to value ( ):- Code: code R s bits in \$4: in \$5: in \$6: in \$5: in \$5: in \$6: and or Code: assume code in \$4 // get masking value in \$5 lui ori \$5, 0xfc1f \$5, \$5, 0xffff and \$6, \$5, \$4 // new value into \$5 addiu \$5, \$0, 0x15 sll \$5, \$5, 21 or \$6, \$6, \$5 What is wanted.

6 Shift Instructions: Shift left logical: sll rd, rt, shift-amount rd rt << shift-amount : 0s placed on right Example: Let \$4 == 2, then sll \$5, \$4, 3 shifts the contents of \$4 left 3 places: (2<<3) 16 which is stored in \$ :shift left 1 2:shift left 1 3:shift left

7 shift left logical variable: sllv rd, rt, rs : rs holds shift- amount for shifting rt with result into rd : rd rt << rs shift right logical: reverse of shift left logical srl rd, rt, shift-amount : 0s placed on left e.g. \$5 = 16 then srl \$6, \$5, 3 : \$6 16 >> 3 \$6 == 2 after instruction shift right logical variable: srlv rd, rt, rs as sllv but shift right Shift right arithmetic: shift right with sign duplication shift right arithmetic: sra rd, rt, shift-amount shift right arithmetic variable: srav rd, rt, rs arithmetic shifts duplicate the sign bit : 1s are placed on right for -ve values (>> 2) (>> 2)

8 Branches - a Reminder!!!!! Instructions are always 4 bytes long in Mips. Instructions are always stored at addresses that are an integer multiple of 4:- 0, 4, 8, 0x2C, 0x30,. 0x , 0x C.. pc always points at an instruction, i.e. pc always holds a multiple of 4 Branches always change pc by a multiple of 4 Branch offset is number of instructions to branch, not number of addresses! Branch target address calculation:- pc + (offset *4)

9 Conditional Branch Instructions using labels calculating offsets is difficult use a label instead! you write this Branch Equal assembler calculates this beq rs, rt, Label : if rs == rt pc <- pc + (address of label pc) : if rs == rt pc <- pc + offset*4 Branch Not-Equal bne reg1, reg2, Label : if rs!= rt pc <- pc + (address of label pc) : if rs!= rt pc <- pc + offset*4 Assembler Program calculates difference between address of instruction following the branch and the address of Label (label address pc), divides by 4 and stores this value, the number of insructions to branch, in offset field of instruction. 6 Bits 5 Bits 5 Bits 16-bit op rs rt offset

10 Other Branches These branches test the contents of a single register against 0. branch on greater than or equal zero: bgez register, label : if (register >= 0) pc address of label : if (register >= 0) pc pc + offset*4 branch on greater than zero: bgtz register, label : if (register > 0) pc address of label : if (register > 0) pc pc + offset*4 branch on less than or equal zero: blez register, label : if (register <= 0) pc address of label : if (register <= 0) pc pc + offset*4 branch on less than zero: bltz register, label : if (register < 0) pc address of label : if (register > 0) pc pc + offset*4 Note: branches can only go instructions back & forward memory address space in Mips is 1G instructions!!!!!!!!!!

11 What about comparing 2 registers for < and >=? Use a Set instruction followed by a conditional branch. Comparison Instructions R-Format versions: compare 2 register and put result into 3 rd register Set less than (signed): slt rd, rs, rt : if rs<rt set rd=1 else set rd=0 Set less than unsigned: sltu rd, rs, rt : if rs<rt set rd=1 else set rd=0 I-Format versions: compare register and constant, put result into 2 nd register Set less than immediate (signed): slti rd, rs, imm : if rs<imm set rd=1 else set rd=0 Set less than unsigned immediate: sltui rd, rs, imm : if rs<imm set rd=1 else set rd=0 The immediate value, (imm), is 16-bits and is sign-extended to 32 bits before comparison. Use beq or bne against reg \$0 to test result register rd after set.

12 MIPS for loop example Setting the elements of an array to zero Data declarations:- unsigned i ; int array[10] ; N.B. C creates the space for both these automatically no new required. for (i=0; i<10; i++) { array[i] = 0 ; }

13 i=0 MIPS for loop example Let the variable i be stored in register \$4 Let int array start at address Each integer occupies 4 addresses Use \$8 and \$9 for temporary storage of intermediate values add \$4, \$0, \$0 : set \$4=0 : 0 i loop: slti \$8, \$4, 10 : set \$8=1 if \$4 < 10 otherwise \$8=0 beq \$8, \$0, end : if \$8=0 (\$4>=10) branch to end label lui \$8, 0x1234 : \$8 0x ori \$8, \$8, 0x5678 : \$8 \$8 0x5678 : \$8 =0x sll \$9, \$4, 2 : \$9 \$4 << 2 : \$9 i*4 add \$8, \$8, \$9 : form address of array[i] in \$8 sw \$0, 0(\$8) : store 32-bits of zero from \$0 into array[i] addui \$4, \$4, 1 : i++ i++ end: beq \$0, \$0, loop : branch to label loop - always branches i<10

14 array x x x x x xc 0x x10 0x x14 0x x18 0x x1C 0x x20 0x x24

15 MIPS for loop example Setting the elements of an array to zero, but using pointers to memory addresses! Data declarations (C code NOT Java!!!):- Variable ap is of type pointer to integer and will hold an address (a pointer in C) unsigned i ; int array[10] ; int *ap ; ap = array ; // put the address of array into ap for (i=0; i<10; i++) { } *ap = 0 ; // store 0 in the location pointed to by ap ap++ ; // increment the address in ap by 4 // ap now points at the next element of array

16 array ap 0x x C 0x x x x C 0x x x x C

17 i=0 Let the variable i be stored in register \$4, and variable ap in \$6 Let array of integers be stored at addresses F 16 lui \$6, 0x1234 : \$6 <- 0x ori \$6, \$6, 0x5678 : \$6 <- \$6 0x5678 : \$6 =0x add \$4, \$0, \$0 : set \$4=0 : 0 i loop: slti \$8, \$4, 10 : set \$8=1 if \$4 < 10 otherwise 0 beq \$8, \$0, end : if \$8=0 (\$4>=10) branch to end label sw \$0, 0(\$6) : store 32-bits of zero in \$0 into array[i] *ap=0 ap++ i++ end: MIPS for loop example Use \$8 for temporary storage addui \$6, \$6, 4 : ap++; add4 to \$6 to point to array[i+1] addui \$4, \$4, 1 : i++ ; increment loop variable beq \$0, \$0, loop : branch to label loop - always branches ap = array i<10

18 Other instructions that change the PC: jump register : jr rs : pc <- rs : register contents into pc Register value must be multiple of 4 (or processor stops) pc can be set to anywhere in memory (greater range than branches). This is used to perform function return, e.g. jr \$31, N.B. Jumps can go a greater distance than branches. However jumps are never conditional unlike branches. Both are therefore necessary. jump and link register : jalr rs, rd : rd <- pc ; pc <- rs pc saved to register rd and then rs written into pc Used for function (method) calls to anywhere in the address space.

19 Function (Method or Subroutine) Call Some lines of program 0x0001AB2C 0x0001AB30 0x0001AB34 lui \$1, 0x04 ; \$1 <- 0x x0001AB38 ori \$1, 0x5678 ; \$1 <- 0x x0001AB3C jalr \$1, \$31 ; pc -> \$31, \$1->PC i.e.0x0001ab40->\$31 0x > PC Function call 0x0001AB40 Function return Have to be sure that \$31 has the value store by the jalr when the jr is executed! Code of method 0x x C 0x x x jr \$31 ; \$31->PC i.e.0x01ab40 -> PC

20 Jump Instructions - J Format 6 Bits op 26 Bits target jump to target : j target : pc[bits 27:0]target*4 jump and link target : jal target register 31 <- contents of pc ; pc[bits 27:0]target*4 In both cases lower 28 bits of PC register are loaded with (26 bits of target field * 4) jal is a method call instruction saving the PC before changing it. Detail : pc is always an integer multiple of 4: therefore value stored in target field of instruction for j and jal is target address divided by 4, i.e. least 2 bits are dropped, since they are always 00. Note: the upper 4-bits of PC are unchanged by these instructions.

### MIPS Instruction Reference

Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly

### MIPS Reference Guide

MIPS Reference Guide Free at PushingButtons.net 2 Table of Contents I. Data Registers 3 II. Instruction Register Formats 4 III. MIPS Instruction Set 5 IV. MIPS Instruction Set (Extended) 6 V. SPIM Programming

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

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

### MIPS%Assembly% E155%

MIPS%Assembly% E155% Outline MIPS Architecture ISA Instruction types Machine codes Procedure call Stack 2 The MIPS Register Set Name Register Number Usage \$0 0 the constant value 0 \$at 1 assembler temporary

### SPIM Instruction Set

SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

### MIPS Instruction Format

MIPS Instruction Format MIPS uses a 32-bit fixed-length instruction format. only three different instruction word formats: There are Register format Op-code Rs Rt Rd Function code 000000 sssss ttttt ddddd

### EE108B Lecture 3. MIPS Assembly Language II

EE108B Lecture 3 MIPS Assembly Language II Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b 1 Announcements Urgent: sign up at EEclass and say if you are taking 3 or 4 units Homework

### Midterm. CS64 Spring Midterm Exam

Midterm LAST NAME FIRST NAME PERM Number Instructions Please turn off all pagers, cell phones and beepers. Remove all hats & headphones. Place your backpacks, laptops and jackets at the front. Sit in every

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

A Processor Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 2.16-20, 4.1-3 Let s build a MIPS CPU but using Harvard architecture Basic Computer System Registers ALU

### Week 10: Assembly Programming

Week 10: Assembly Programming Arithmetic instructions Instruction Opcode/Function Syntax Operation add 100000 \$d, \$s, \$t \$d = \$s + \$t addu 100001 \$d, \$s, \$t \$d = \$s + \$t addi 001000 \$t, \$s, i \$t = \$s +

### Concocting an Instruction Set

Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Read: Chapter 2.1-2.7 L03 Instruction Set 1 A General-Purpose Computer The von

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

page 1 Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... A General-Purpose Computer The von Neumann Model Many architectural approaches

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

Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

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

ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

### Assembly Programming

Designing Computer Systems Assembly Programming 08:34:48 PM 23 August 2016 AP-1 Scott & Linda Wills Designing Computer Systems Assembly Programming In the early days of computers, assembly programming

### CS 4200/5200 Computer Architecture I

CS 4200/5200 Computer Architecture I MIPS Instruction Set Architecture Dr. Xiaobo Zhou Department of Computer Science CS420/520 Lec3.1 UC. Colorado Springs Adapted from UCB97 & UCB03 Review: Organizational

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

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5 MIPS/SPIM General Purpose Registers Powers of Two 0 \$zero all bits are zero 16 \$s0 local variable 1 \$at assembler temporary 17 \$s1 local

### ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

ICS 233 COMPUTER ARCHITECTURE MIPS Processor Design Multicycle Implementation Lecture 23 1 Add immediate unsigned Subtract unsigned And And immediate Or Or immediate Nor Shift left logical Shift right

### Announcements. EE108B Lecture MIPS Assembly Language III. MIPS Machine Instruction Review: Instruction Format Summary

Announcements EE108B Lecture MIPS Assembly Language III Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b PA1 available, due on Thursday 2/8 Work on you own (no groups) Homework

### Concocting an Instruction Set

Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Lab is posted. Do your prelab! Stay tuned for the first problem set. L04 Instruction

### ECE Exam I February 19 th, :00 pm 4:25pm

ECE 3056 Exam I February 19 th, 2015 3:00 pm 4:25pm 1. The exam is closed, notes, closed text, and no calculators. 2. The Georgia Tech Honor Code governs this examination. 3. There are 4 questions and

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

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer

### ECE 2035 A Programming Hw/Sw Systems Spring problems, 8 pages Final Exam 29 April 2015

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

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

Department of Electrical and Computer Engineering University of Wisconsin Madison ECE 552 Introductions to Computer Architecture Homework #2 (Suggested Solution) 1. (10 points) MIPS and C program translations

### MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS ISA and MIPS Assembly CS301 Prof. Szajda Administrative HW #2 due Wednesday (9/11) at 5pm Lab #2 due Friday (9/13) 1:30pm Read Appendix B5, B6, B.9 and Chapter 2.5-2.9 (if you have not already done

### Architecture II. Computer Systems Laboratory Sungkyunkwan University

MIPS Instruction ti Set Architecture II Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Making Decisions (1) Conditional operations Branch to a

### MIPS PROJECT INSTRUCTION SET and FORMAT

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

### CS3350B Computer Architecture

CS3350B Computer Architecture Winter 2015 Lecture 4.1: MIPS ISA: Introduction Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted d from lectures on Computer Organization and Design, Patterson & Hennessy,

### Lecture 6 Decision + Shift + I/O

Lecture 6 Decision + Shift + I/O Instructions so far MIPS C Program add, sub, addi, multi, div lw \$t0,12(\$s0) sw \$t0, 12(\$s0) beq \$s0, \$s1, L1 bne \$s0, \$s1, L1 j L1 (unconditional branch) slt reg1,reg2,reg3

### MIPS Assembly Programming

COMP 212 Computer Organization & Architecture COMP 212 Fall 2008 Lecture 8 Cache & Disk System Review MIPS Assembly Programming Comp 212 Computer Org & Arch 1 Z. Li, 2008 Comp 212 Computer Org & Arch 2

### Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

Computer Organization MIPS Architecture Department of Computer Science Missouri University of Science & Technology hurson@mst.edu Computer Organization Note, this unit will be covered in three lectures.

### CPS311 - COMPUTER ORGANIZATION. A bit of history

CPS311 - COMPUTER ORGANIZATION A Brief Introduction to the MIPS Architecture A bit of history The MIPS architecture grows out of an early 1980's research project at Stanford University. In 1984, MIPS computer

### MIPS (SPIM) Assembler Syntax

MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

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

Computer Science 324 Computer Architecture Mount Holyoke College Fall 2009 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

Operands and Addressing Modes Where is the data? Addresses as data Names and Values Indirection L5 Addressing Modes 1 Assembly Exercise Let s write some assembly language programs Program #1: Write a function

### ECE 2035 A Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 14 December 2016

Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

### Review of the Machine Cycle

MIPS Branch and Jump Instructions Cptr280 Dr Curtis Nelson Review of the Machine Cycle When a program is executing, its instructions are located in main memory. The address of an instruction is the address

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

Register names (save, temporary, zero) From what I have said up to now, you will have the impression that you are free to use any of the 32 registers (\$0,..., \$31) in any instruction. This is not so, however.

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

Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

### Chapter loop: lw \$v1, 0(\$a0) addi \$v0, \$v0, 1 sw \$v1, 0(\$a1) addi \$a0, \$a0, 1 addi \$a1, \$a1, 1 bne \$v1, \$zero, loop

Chapter 3 3.7 loop: lw \$v1, 0(\$a0) addi \$v0, \$v0, 1 sw \$v1, 0(\$a1) addi \$a0, \$a0, 1 addi \$a1, \$a1, 1 bne \$v1, \$zero, loop Instructions Format OP rs rt Imm lw \$v1, 0(\$a0) I 35 4 3 0 addi \$v0, \$v0, 1 I 8

### We will study the MIPS assembly language as an exemplar of the concept.

MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

### EE 109 Unit 8 MIPS Instruction Set

1 EE 109 Unit 8 MIPS Instruction Set 2 Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system

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

Computer Science and Engineering 331 Midterm Examination #1 Fall 2000 Name: Solutions S.S.#: 1 41 2 13 3 18 4 28 Total 100 Instructions: This exam contains 4 questions. It is closed book and notes. Calculators

### CSc 256 Final Spring 2011

CSc 256 Final Spring 2011 NAME: Problem1: Convertthedecimalfloatingpointnumber 4.3toa32 bitfloat(inbinary)inieee 754standardrepresentation.Showworkforpartialcredit.10points Hint:IEEE754formatfor32 bitfloatsconsistsofs

### Digital System Design II

Digital System Design II 数字系统设计 II Peng Liu ( 刘鹏 ) Dept. of Info. Sci. & Elec. Engg. Zhejiang University liupeng@zju.edu.cn Lecture 2 MIPS Instruction Set Architecture 2 Textbook reading MIPS ISA 2.1-2.4

### CPU Design for Computer Integrated Experiment

CPU Design for Computer Integrated Experiment Shan Lu, Guangyao Li, Yijianan Wang CEIE, Tongji University, Shanghai, China Abstract - Considering the necessity and difficulty of designing a CPU for students,

### Problem maximum score 1 35pts 2 22pts 3 23pts 4 15pts Total 95pts

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Sciences CS61c Summer 2001 Woojin Yu Midterm Exam This is a closed-book exam. No calculators

### Field 6-Bit Op Code rs Field rt Field 16-bit Immediate field

Introduction to MIPS Instruction Set Architecture The MIPS used by SPIM is a 32-bit reduced instruction set architecture with 32 integer and 32 floating point registers. Other characteristics are as follows:

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

Today s topics CS/COE1541: Introduction to Computer Architecture MIPS operations and operands MIPS registers Memory view Instruction encoding A Review of MIPS ISA Sangyeun Cho Arithmetic operations Logic

EE 352 Unit 3 MIPS ISA Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system Instruction set is the vocabulary the HW can understand and the SW is composed

### Mark Redekopp, All rights reserved. EE 352 Unit 4. Assembly and the MARS Simulator Control Flow (Branch Instructions)

EE 352 Unit 4 Assembly and the MARS Simulator Control Flow (Branch Instructions) Directives Pseudo-instructions ASSEMBLERS Assembler Syntax In MARS and most assemblers each line of the assembly program

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

Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

### The Program Counter. QtSPIM Register Display (Fixed-Point Registers) Erik Jonsson School of Engineering and Computer Science

The Program Counter PC = 400064 EPC = 0 Cause = 0 BadVAddr = 0 Status = 3000ff10 1 The program counter is a register that always contains the memory address of the next instruction (i.e., the instruction

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

CSE 675.02: Introduction to Computer Architecture MIPS Processor Memory Instruction Set Architecture of MIPS Processor CPU Arithmetic Logic unit Registers \$0 \$31 Multiply divide Coprocessor 1 (FPU) Registers

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

Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn Computer Hierarchy Levels Language understood

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

Computer Science 324 Computer Architecture Mount Holyoke College Fall 2007 Topic Notes: MIPS Instruction Set Architecture vonneumann Architecture Modern computers use the vonneumann architecture. Idea:

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures \$2M 3D camera Lecture 8 MIPS Instruction Representation I Instructor: Miki Lustig 2014-09-17 August 25: The final ISA showdown: Is ARM, x86, or

### The MIPS R2000 Instruction Set

The MIPS R2000 Instruction Set Arithmetic and Logical Instructions In all instructions below, Src2 can either be a register or an immediate value (a 16 bit integer). The immediate forms of the instructions

### All instructions have 3 operands Operand order is fixed (destination first)

Instruction Set Architecture for MIPS Processors Overview Dr. Arjan Durresi Louisiana State University Baton Rouge, LA 70803 durresi@csc.lsu.edu These slides are available at: http://www.csc.lsu.edu/~durresi/_07/

### Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

Review (1/2) CS61C - Machine Structures Lecture 11 - Starting a Program October 4, 2000 David Patterson http://www-inst.eecs.berkeley.edu/~cs61c/ IEEE 754 Floating Point Standard: Kahan pack as much in

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

Outline EEL-4713 Computer Architecture Multipliers and shifters Multiplication and shift registers Chapter 3, section 3.4 Next lecture Division, floating-point 3.5 3.6 EEL-4713 Ann Gordon-Ross.1 EEL-4713

### Adding Support for jal to Single Cycle Datapath (For More Practice Exercise 5.20)

Adding Support for jal to Single Cycle Datapath (For More Practice Exercise 5.20) The MIPS jump and link instruction, jal is used to support procedure calls by jumping to jump address (similar to j ) and

### MIPS Instructions: 64-bit Core Subset

MIPS Instructions: 64-bit Core Subset Spring 2008 General notes: a. R s, R t, and R d specify 64-bit general purpose registers b. F s, F t, and F d specify 64-bit floating point registers c. C d specifies

### Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi \$s2, \$s2, -1 beq \$s0, \$s1, loop or \$s2, \$s1, \$zero

Do-While Example In C++ do { z--; while (a == b); z = b; In assembly language loop: addi \$s2, \$s2, -1 beq \$s0, \$s1, loop or \$s2, \$s1, \$zero 25 Comparisons Set on less than (slt) compares its source registers

### CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

CS61C L1 MIPS Instruction Representation II, Floating Point I (1) inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #1 Instruction Representation II, Floating Point I 25-1-3 There is one

### ISA: The Hardware Software Interface

ISA: The Hardware Software Interface Instruction Set Architecture (ISA) is where software meets hardware In embedded systems, this boundary is often flexible Understanding of ISA design is therefore important

### Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Instructions (354 Review) Forecast Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary With a few other things, this defines the interface of computers But implementations

### COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access

### COMP 303 MIPS Processor Design Project 3: Simple Execution Loop

COMP 303 MIPS Processor Design Project 3: Simple Execution Loop Due date: November 20, 23:59 Overview: In the first three projects for COMP 303, you will design and implement a subset of the MIPS32 architecture

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #9: MIPS Procedures 2006-07-11 CS 61C L09 MIPS Procedures (1) Andy Carle C functions main() { int i,j,k,m;... i = mult(j,k);... m =

### Solutions for Chapter 2 Exercises

Solutions for Chapter 2 Exercises 1 Solutions for Chapter 2 Exercises 2.2 By lookup using the table in Figure 2.5 on page 62, 7fff fffa hex = 0111 1111 1111 1111 1111 1111 1111 1010 two = 2,147,483,642

### Harnessing FPGAs for Computer Architecture Education

Harnessing FPGAs for Computer Architecture Education Mark Holland, James Harris, Scott Hauck Department of Electrical Engineering University of Washington, Seattle, WA 98195, USA mholland@ee.washington.edu,

### CS61C Machine Structures. Lecture 10 - MIPS Branch Instructions II. 2/8/2006 John Wawrzynek. (www.cs.berkeley.edu/~johnw)

CS61C Machine Structures Lecture 10 - MIPS Branch Instructions II 2/8/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L10 MIPS Branch II (1) Compiling C if into

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 14 Introduction to MIPS Instruction Representation II Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Are you P2P sharing fans? Two

### Lab 4 Report. Single Cycle Design BAOTUNG C. TRAN EEL4713C

Lab 4 Report Single Cycle Design BAOTUNG C. TRAN EEL4713C Added Hardware : Andi and Ori : For this instruction, I had to add a zero extender into my design. Which therefore required me to add a mux that

### HW2 solutions You did this for Lab sbn temp, temp,.+1 # temp = 0; sbn temp, b,.+1 # temp = -b; sbn a, temp,.+1 # a = a (-b) = a + b;

HW2 solutions 3.10 Pseuodinstructions What is accomplished Minimum sequence of Mips Move \$t5, \$t3 \$t5=\$t3 Add \$t5, \$t3, \$0 Clear \$t5 \$t5=0 Xor \$t5, \$t5, \$t5 Li \$t5, small \$t5=small Addi \$t5, \$0, small

### CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #10 Instruction Representation II, Floating Point I 2005-10-03 Lecturer PSOE, new dad Dan Garcia www.cs.berkeley.edu/~ddgarcia #9 bears

### Architecture I. Computer Systems Laboratory Sungkyunkwan University

MIPS Instruction ti Set Architecture I Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Architecture (1) the attributes of a system as seen by the

### CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats

CS 61C: Great Ideas in Computer Architecture MIPS Instruction Formats Instructors: Vladimir Stojanovic and Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Machine Interpretation Levels of Representation/Interpretation

### ECE 2035 Programming HW/SW Systems Spring problems, 7 pages Exam One Solutions 4 February 2013

Problem 1 (3 parts, 30 points) Code Fragments Part A (5 points) Write a MIPS code fragment that branches to label Target when register \$1 is less than or equal to register \$2. You may use only two instructions.

### RISC, CISC, and Assemblers

RISC, CISC, and Assemblers Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix B.1 2, and Chapters 2.8 and 2.12; als 2.16 and 2.17 Big Picture: Understanding Tradeoffs

### CSE Lecture In Class Example Handout

CSE 30321 Lecture 07-08 In Class Example Handout Part A: J-Type Example: If you look in your book at the syntax for j (an unconditional jump instruction), you see something like: e.g. j addr would seemingly

### Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?

### Shift and Rotate Instructions

Shift and Rotate Instructions Shift and rotate instructions facilitate manipulations of data (that is, modifying part of a 32-bit data word). Such operations might include: Re-arrangement of bytes in a

### Recall that an assembler translates code written in mnemonic form in assembly language into machine code.

The Assignment Recall that an assembler translates code written in mnemonic form in assembly language into machine code. You will implement an assembler that supports a subset of the MIPS32 assembly language

### Chapter 2. Instruction Set Architecture (ISA)

Chapter 2 Instruction Set Architecture (ISA) MIPS arithmetic Design Principle: simplicity favors regularity. Why? Of course this complicates some things... C code: A = B + C + D; E = F - A; MIPS code:

### CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture

CS 61C: Great Ideas in Computer Architecture Introduction to Assembly Language and MIPS Instruction Set Architecture Instructors: Bernhard Boser & Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa16

### EE 109 Unit 15 Subroutines and Stacks

1 EE 109 Unit 15 Subroutines and Stacks 2 Program Counter and GPRs (especially \$sp, \$ra, and \$fp) REVIEW OF RELEVANT CONCEPTS 3 Review of Program Counter PC is used to fetch an instruction PC contains

### CS3350B Computer Architecture MIPS Procedures and Compilation

CS3350B Computer Architecture MIPS Procedures and Compilation Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada

### Welcome to CS250 VLSI Systems Design

Image Courtesy: Intel Welcome to CS250 VLSI Systems Design 9/2/10 Yunsup Lee YUNSUP LEE Email: yunsup@cs.berkeley.edu Please add [CS250] in the subject Will try to get back in a day CS250 Newsgroup Post

### CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats

CS 61C: Great Ideas in Computer Architecture RISC-V Instruction Formats Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 9/14/17 Fall 2017 - Lecture #7 1 Levels of

Assemblers and Linkers Long, long, time ago, I can still remember How mnemonics used to make me smile... Cause I knew that with those opcode names that I could play some assembly games and I d be hacking

### CO Computer Architecture and Programming Languages CAPL. Lecture 13 & 14

CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 13 & 14 Dr. Kinga Lipskoch Fall 2017 Frame Pointer (1) The stack is also used to store variables that are local to function, but

### UCB CS61C : Machine Structures

inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 10 Introduction to MIPS Procedures I Sr Lecturer SOE Dan Garcia 2014-02-14 If cars broadcast their speeds to other vehicles (and the

### Patterson PII. Solutions

Patterson-1610874 978-0-12-407726-3 PII 2 Solutions Chapter 2 Solutions S-3 2.1 addi f, h, -5 (note, no subi) add f, f, g 2.2 f = g + h + i 2.3 sub \$t0, \$s3, \$s4 add \$t0, \$s6, \$t0 lw \$t1, 16(\$t0) sw \$t1,

### CS152 Computer Architecture and Engineering. Lecture 1 Introduction & MIPS Review Dave Patterson. www-inst.eecs.berkeley.

CS152 Computer Architecture and Engineering Lecture 1 Introduction & MIPS Review 2003-08-26 Dave Patterson (www.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs152/ CS 152 L01 Introduction &

### Inequalities in MIPS (2/4) Inequalities in MIPS (1/4) Inequalities in MIPS (4/4) Inequalities in MIPS (3/4) UCB CS61C : Machine Structures

CS61C L8 Introduction to MIPS : Decisions II & Procedures I (1) Instructor Paul Pearce inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures http://www.xkcd.org/627/ Lecture 8 Decisions & and Introduction

### ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 4: Datapath and Control

ELEC 52/62 Computer Architecture and Design Spring 217 Lecture 4: Datapath and Control Ujjwal Guin, Assistant Professor Department of Electrical and Computer Engineering Auburn University, Auburn, AL 36849