# 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

Save this PDF as:

Size: px
Start display at page:

Download "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"

## Transcription

1 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

2 Comparisons Set on less than (slt) compares its source registers and sets its destination register to 1 if src1 < src2 and to 0 otherwise (branch-if-less-than) Syntax: slt dest, src1, src2 Set on less than immediate (slti) perform the same comparison, but its second source operation is an immediate value Syntax: slti dest, src1, immed Combined with beq and bne these instructions can implement all possible relational operators 26

3 Relational Branches (1) Branch if less than slt \$t0, src1, src2 bne \$zero, \$t0, label Branch if greater than or equal slt \$t0, src1, src2 beq \$zero, \$t0, label 27

4 Relational Branches (2) Branch if greater than slt \$t0, src2, src1 bne \$zero, \$t0, label Branch if less than or equal slt \$t0, src2, src1 beq \$zero, \$t0, label 28

5 Case/Switch Statement * Can be implemented like a chain of if-thenelse statements Using a jump address table is faster Must be able to jump to an address loaded from memory Jump register (jr) gives us that ability Syntax: jr src Instruction: jr \$t1 #go to address in \$t1 29

6 Compiling a Case (Switch) Statement Memory switch (k) { case 0: h=i+j; break; /*k=0*/ case 1: h=i+h; break; /*k=1*/ case 2: h=i-j; break; /*k=2*/ Assuming three sequential words in memory starting at the address in \$t4 have the addresses of the labels L0, L1, and L2 and k is in \$s2 \$t4 add \$t1, \$s2, \$s2 #\$t1 = 2*k add \$t1, \$t1, \$t1 #\$t1 = 4*k add \$t1, \$t1, \$t4 #\$t1 = addr of JumpT[k] lw \$t0, 0(\$t1) #\$t0 = JumpT[k] jr \$t0 #jump based on \$t0 L0: add \$s3, \$s0, \$s1 #k=0 so h=i+j j Exit L1: add \$s3, \$s0, \$s3 #k=1 so h=i+h j Exit L2: sub \$s3, \$s0, \$s1 #k=2 so h=i-j Exit:... L2 L1 L0 30

7 MIPS Organization src1 addr 5 src2 addr 5 dst addr 5 write data 32 Processor Register File 32 registers (\$zero - \$ra) 32 bits src1 data src2 data read/write addr 32 Memory words Exec br offset PC 32 Add 32 4 Fetch 32 PC = PC+4 Decode Add 32 ALU 32 read data write data byte address (big Endian) 32 bits word address (binary) 31

8 Variable Index into Array Previous method for accessing array elements will only work if index is constant If index is a variable we must compute the address in code Formula: address + (index width) Since width is usually a power of two, we can use a left shift to perform the multiplication 32

9 Structures Like an array, a structure (struct) is made up of several smaller data elements stored contiguously in memory However the elements do not have to all be the same type The compiler will construct a table mapping each structure member to an offset 33

10 Bit Fields Structure members can be bit fields In this case multiple members are packed into a single byte or word To retrieve the value of a bit field, AND the word with a mask and then shift right To set the value of a bit field use a left shift and an OR 34

11 Procedures * A function (or procedure) is a sequence of instructions that can be used to perform a task When a function is called control transfers to the function; once the function completes its task it returns Functions may accept parameters (arguments) and/or return a value A function can also define local variables for its use which exist only until the function returns Functions can call other functions 35

12 Call and Return Call and return are nothing more than unconditional jumps The calling function (the caller) jumps to the beginning of the function The called function (the callee) jumps back to the point from which it was called (return address) Since a function can be called from any number of places the return address changes with each call 36

13 Jump and Link The jump and link (jal) instruction performs an unconditional jump just like j, but first saves the address of the next instruction in the return address register (\$ra) jal label A function returns by jumping to the address stored in that register: jr \$ra 37

14 Example (1) Calling a function: jal function1 Function: function1: add \$t0, \$t1, \$t2 sub \$t3, \$t4, \$t5 jr \$ra 38

15 Calling Conventions We need a way to pass parameters to a function and get a return value from it A calling convention is a set of rules that define how parameters and return values are passed to/from functions as well as which registers a function can use Allows us to call functions compiled by different compilers and even languages 39

16 Parameters/Return Value Most MIPS software uses the same calling convention The first four parameters are placed in registers (\$a0-\$a3) additional parameters are placed on the stack Return values go in registers \$v0-\$v1 40

17 MIPS Registers Name Number Usage Saved on Call? \$zero 0 Zero (hardware) N/A \$at 1 reserved Assembler Temp No \$v0-\$v1 2-3 Return Value/Temporaries No \$a0-\$a3 4-7 Arguments No \$t0-\$t9 8-15, Temporaries No \$s0-\$s Saved Values Yes \$k0-\$k Reserved for OS Kernel No \$gp 28 Global Pointer Yes \$sp 29 Stack Pointer Yes \$fp 30 Frame Pointer Yes \$ra 31 Return Address (hardware) Yes 41

18 Example (2) Function call or \$a0, \$s0, \$zero jal function2 or \$s0, \$v0, \$zero Function definition function2: add \$v0, \$a0, \$a0 jr \$ra 42

19 Register Use Callee-saved registers are owned by caller; if a function uses a callee-saved register it must save the old value and restore that value before it returns Caller-saved registers are owned by the callee; if a caller is using a caller-saved register, it must save the old value before calling the function and restore it after the function returns In MIPS, \$s0-\$s7 are callee-saved and \$t0-\$t9 are caller-saved 43

20 The Stack Data that a function needs to save in memory is pushed onto the stack Before returning, the function pops the data off of the stack In MIPS, the stack pointer (\$sp) contains the address of the last word pushed onto the stack The stack grows downward from higher addresses to lower ones 44

21 Spilling Registers What if the callee needs more registers? What if the procedure is recursive? high addr uses a stack a last-in-first-out queue in memory for passing additional values or saving (recursive) return address(es) One of the general registers, \$sp, is used to address the stack (which grows from high address to low address) add data onto the stack push top of stack \$sp \$sp = \$sp 4 data on stack at new \$sp remove data from the stack pop low addr data from stack at \$sp \$sp = \$sp

22 Accessing the Stack Push a word onto the stack addi \$sp, \$sp, -4 sw src, 0(\$sp) Pop a word off of the stack lw dest, 0(\$sp) addi \$sp, \$sp, 4 Typically we batch multiple pushes and pops together 46

23 Accessing the Stack (cont'd) Push three words onto the stack addi \$sp, \$sp, -12 sw \$t0, 8(\$sp) sw \$t1, 4(\$sp) sw \$s0, 0(\$sp) Pop three words off of the stack lw \$s0, 0(\$sp) lw \$t1, 4(\$sp) lw \$t0, 8(\$sp) addi \$sp, \$sp, 12 47

24 Stack Illustration High address \$sp \$sp Contents of register \$t1 Contents of register \$t0 \$sp Contents of register \$s0 Low address a. b. c. 48

25 Data on the Stack Data a function puts on the stack makes up its stack frame or activation record If there are more than four parameters, the extra parameters must be pushed onto the stack Non-leaf functions must save the value of the return address register (\$ra) 49

26 Data on the Stack (cont'd) Any registers that must be saved are stored on the stack Also local variables that won't fit into registers (either because there are no registers left or the data is too big) Commonly a frame pointer (\$fp) is used in addition to the stack pointer, since the stack pointer could change during the function 50

27 Stack Frame High address \$fp \$fp \$sp \$sp \$fp Saved argument registers (if any) Saved return address Saved saved registers (if any) Local arrays and structures (if any) \$sp Low address a. b. c. 51

28 Where Data is Stored The static data area holds global variables Fixed size In MIPS, the global pointer (\$gp) contains the address of this area The stack holds local variables and functionrelated information Dynamic and managed automatically by the compiler The heap holds data allocated through new or malloc Dynamic and managed by the programmer 52

29 hex Text Program Memory \$sp 7fff ffff hex Stack Dynamic data \$gp hex Static data pc hex 0 Reserved 53

30 MIPS Registers Name Number Usage Saved on Call? \$zero 0 Zero N/A \$at 1 Assembler Temporary No \$v0-\$v1 2-3 Return Value/Temporaries No \$a0-\$a3 4-7 Arguments No \$t0-\$t9 8-15, Temporaries No \$s0-\$s Saved Yes \$k0-\$k Reserved for OS Kernel No \$gp 28 Global Pointer Yes \$sp 29 Stack Pointer Yes \$fp 30 Frame Pointer Yes \$ra 31 Return Address Yes 54

### 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

### 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

### 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

### Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1

### 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

### CS 61c: Great Ideas in Computer Architecture

MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: \$s0-\$s7,\$t0-\$t9, \$0

### CSE Lecture In Class Example Handout

CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A

### 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

### 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

### 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

### CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions

CS 61C: Great Ideas in Computer Architecture More RISC-V Instructions and How to Implement Functions Instructors: Krste Asanović and Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/fa17 9/14/17 Fall

### 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,

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

EN164: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown

### 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

### 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

### Lecture 5. Announcements: Today: Finish up functions in MIPS

Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In

### 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

### 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

### 2. dead code elimination (declaration and initialization of z) 3. common subexpression elimination (temp1 = j + g + h)

Problem 1 (20 points) Compilation Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version (in C) to the right. Assume f is a pure function

### 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

### 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

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

### Functions and Procedures

Functions and Procedures Function or Procedure A separate piece of code Possibly separately compiled Located at some address in the memory used for code, away from main and other functions (main is itself

### 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?

### Procedure Call and Return Procedure call

Procedures int len(char *s) { for (int l=0; *s!= \0 ; s++) l++; main return l; } void reverse(char *s, char *r) { char *p, *t; int l = len(s); reverse(s,r) N/A *(r+l) = \0 ; reverse l--; for (p=s+l t=r;

### Review of Activation Frames. FP of caller Y X Return value A B C

Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C

### CS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons

CS 61C: Great Ideas in Computer Architecture Strings and Func.ons Instructor: Krste Asanovic, Randy H. Katz hdp://inst.eecs.berkeley.edu/~cs61c/sp12 Fall 2012 - - Lecture #7 1 New- School Machine Structures

### 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

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

2.9 Communication with People: Byte Data & Constants Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21 32: space 33:! 34: 35: #...

### Implementing Procedure Calls

1 / 39 Implementing Procedure Calls February 18 22, 2013 2 / 39 Outline Intro to procedure calls Caller vs. callee Procedure call basics Calling conventions The stack Interacting with the stack Structure

### Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.) COS / ELE 375 Computer Architecture and Organization Princeton University Fall 2015 Prof. David August 1 Review: Instructions Computers process information

### 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:

### EN164: Design of Computing Systems Lecture 11: Processor / ISA 4

EN164: Design of Computing Systems Lecture 11: Processor / ISA 4 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University

### 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

### 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/

### Procedure Calls Main Procedure. MIPS Calling Convention. MIPS-specific info. Procedure Calls. MIPS-specific info who cares? Chapter 2.7 Appendix A.

MIPS Calling Convention Chapter 2.7 Appendix A.6 Procedure Calls Main Procedure Call Procedure Call Procedure Procedure Calls Procedure must from any call Procedure uses that main was using We need a convention

### COMP2611: Computer Organization MIPS function and recursion

COMP2611 Fall2015 COMP2611: Computer Organization MIPS function and recursion Overview 2 You will learn the following in this lab: how to use MIPS functions in a program; the concept of recursion; how

### 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

### 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:

### Numbers: positional notation. CS61C Machine Structures. Faux Midterm Review Jaein Jeong Cheng Tien Ee. www-inst.eecs.berkeley.

CS 61C Faux Midterm Review (1) CS61C Machine Structures Faux Midterm Review 2002-09-29 Jaein Jeong Cheng Tien Ee www-inst.eecs.berkeley.edu/~cs61c/ Numbers: positional notation Number Base B B symbols

### 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

### Compilers and computer architecture: A realistic compiler to MIPS

1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

### 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

### 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 =

### 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 Single Cycle Processor

EECS 322 Computer Architecture The Single Cycle Processor Instructor: Francis G. Wolff wolff@eecs.cwru.edu Case Western Reserve University This presentation uses powerpoint animation: please viewshow CWRU

### ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points) Objectives: Get familiar with MIPS instructions Assemble, execute and debug MIPS

### Chapter 4. The Processor. Computer Architecture and IC Design Lab

Chapter 4 The Processor Introduction CPU performance factors CPI Clock Cycle Time Instruction count Determined by ISA and compiler CPI and Cycle time Determined by CPU hardware We will examine two MIPS

### Lecture 6: Assembly Programs

Lecture 6: Assembly Programs Today s topics: Procedures Examples Large constants The compilation process A full example 1 Procedures Local variables, AR, \$fp, \$sp Scratchpad and saves/restores, \$fp Arguments

### MIPS Procedure Calls. Lecture 6 CS301

MIPS Procedure Calls Lecture 6 CS301 Function Call Steps Place parameters in accessible location Transfer control to function Acquire storage for procedure variables Perform calculations in function Place

### Compiling Techniques

Lecture 10: An Introduction to MIPS assembly 18 October 2016 Table of contents 1 Overview 2 3 Assembly program template.data Data segment: constant and variable definitions go here (including statically

### 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

### Procedures and Stacks

Procedures and Stacks Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. March 15, 2018 L10-1 Announcements Schedule has shifted due to snow day Quiz 2 is now on Thu 4/12 (one week later)

### 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

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

Problem 1 (20 points) Optimization Perform at least five standard compiler optimizations on the following C code fragment by writing the optimized version (in C) to the right. Assume f and g are pure functions

### 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,

### 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

Threads and Concurrency 1 Threads and Concurrency key concepts threads, concurrent execution, timesharing, context switch, interrupts, preemption reading Three Easy Pieces: Chapter 26 (Concurrency and

### a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

CS3410 Spring 2015 Problem Set 2 (version 3) Due Saturday, April 25, 11:59 PM (Due date for Problem-5 is April 20, 11:59 PM) NetID: Name: 200 points total. Start early! This is a big problem set. Problem

### 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:

### 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

### Lecture 14: Recap. Today s topics: Recap for mid-term No electronic devices in midterm

Lecture 14: Recap Today s topics: Recap for mid-term No electronic devices in midterm 1 Modern Trends Historical contributions to performance: Better processes (faster devices) ~20% Better circuits/pipelines

### Instruction Set Architecture (Contd)

Instruction Set Architecture (Contd) Lecture 3 (Chapter 2) EEC170 FQ 2005 Review: MIPS Architecture Good example of RISC processor: Reduced Instruction-Set Computer RISC really a misnomer: architecture

### Computer Systems and Networks

LECTURE 16: MIPS (11 AND 12) Computer Systems and Networks Dr. Pallipuram (vpallipuramkrishnamani@pacific.edu) University of the Pacific Deadline Lab 11 is open: DUE 1 st NOV 5 AM Lab 12 is open: DUE 8

### 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

### Arguments and Return Values. EE 109 Unit 16 Stack Frames. Assembly & HLL s. Arguments and Return Values

1 Arguments and Return Values 2 EE 109 Unit 16 Stack Frames MIPS convention is to use certain registers for this task used to pass up to 4 arguments. If more arguments, use the stack used for return value

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

### 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

### 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

### ECE 154A Introduction to. Fall 2012

ECE 154A Introduction to Computer Architecture Fall 2012 Dmitri Strukov Lecture 4: Arithmetic and Data Transfer Instructions Agenda Review of last lecture Logic and shift instructions Load/store instructionsi

### CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 1, 2014 at 12:03 CS429 Slideset 6: 1 Topics

### Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

Part Part Part What if we need to call a function inside of a function? Will this work? int twofun(int a, int b) { int res; res = addfun(a, b) a / ; return res; } twofun: addi \$sp, \$sp, -4 sw \$s0, 0(\$sp)

### 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

### 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

### 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

### 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 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

### 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

### 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

### 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:

### See P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week

### CS64 Week 5 Lecture 1. Kyle Dewey

CS64 Week 5 Lecture 1 Kyle Dewey Overview More branches in MIPS Memory in MIPS MIPS Calling Convention More Branches in MIPS else_if.asm nested_if.asm nested_else_if.asm Memory in MIPS Accessing Memory

EE 352 Unit 6 Stack Frames Recursive Routines Arguments and Return Values MIPS convention is to use certain registers for this task \$a0 - \$a3 used to pass up to 4 arguments. If more arguments, use the

### Procedure Call Instructions

Procedure Calling Steps required 1. Place parameters in registers x10 to x17 2. Transfer control to procedure 3. Acquire storage for procedure 4. Perform procedure s operations 5. Place result in register

### Mips Code Examples Peter Rounce

Mips Code Examples Peter Rounce P.Rounce@cs.ucl.ac.uk 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

### 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

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

Part II Instruction-Set Architecture Jan. 211 Computer Architecture, Instruction-Set Architecture Slide 1 Short review of the previous lecture Performance = 1/(Execution time) = Clock rate / (Average CPI

### Programming at different levels

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014 EMY MNEMONIC MACHINE LANGUAGE PROGRAMMING EXAMPLES Programming at different levels CS1114 Mathematical Problem : a = b + c CS2214 CS2214 The C-like

### 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

### ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H. Lipasti. University of Wisconsin-Madison. Basics Registers and ALU ops

ECE/CS 552: Instruction Sets Instructor:Mikko H. Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill. Instructions (354 Review) Instructions are

### 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

### Stacks and Procedures

Stacks and Procedures I forgot, am I the Caller or Callee? Don t know. But, if you PUSH again I m gonna POP you. Support for High-Level Language constructs are an integral part of modern computer organization.

### 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

### 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

### Control MIPS unconditional branch instruction (i.e., jump)

Control Instruction that potentially changes the flow of program execution MIPS conditional branch instructions bne \$s4, \$s3, LABEL goto LABEL if \$s4!= \$s3 beq \$s4, \$s3, LABEL goto LABEL if \$s4 == \$s3

### 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

### Lab 4 : MIPS Function Calls

Lab 4 : MIPS Function Calls Name: Sign the following statement: On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work 1 Objective The objective of this lab

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

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2 Professor Sherief Reda http://scale.engin.brown.edu Electrical Sciences and Computer Engineering School of Engineering Brown University