# CSE Lecture In Class Example Handout

Save this PDF as:

Size: px
Start display at page:

## Transcription

2 Part B: Procedures with Callee Saving (old exam question): Assume that you have written the following C code: // int variable1 = 10; // global variable int variable2 = 20; // global variable // int (void) { int i = 1; // assigned to register s0 int j = 2; // assigned to register s1 int k = 3; // assigned to register a3 int m; int n; m = addfournumbers(i, j); n = i + j; // = 3 printf( m is %d\n, m); // printf modifies no registers printf( n is %d\n, n); // printf modifies no registers printf( k is %d\n, k); // printf modifies no registers // int addfournumbers(int x, int y) { int i; // assigned to register s0 int j; // assigned to register s1 int k; // assigned to register s2 i = x + y; // = 3 j = variable1 + variable2; // = 30 k = i + j; // = 33 return k; // The output of the printf statements in is: m is 33 n is 3 k is 3 Assume this program was compiled into MIPS assembly language with the register conventions described on Slide 12 of Lecture 07/08. Also, note that in the comments of the program, I have indicated that certain variables will be assigned to certain registers when this program is compiled and assembled. Using a callee calling convention, answer the questions below:

3 Q-i: Ideally, how many arguments to the function addfournumbers must be saved on the stack? 0. By default, arguments should be copied into registers. Q-ii: What (if anything) should the assembly language for () do right before calling addfournumbers? Copy values of s registers into argument registers; save value of k (in \$a3) onto the stack Q-iii: What is the first thing that the assembly language for addfournumbers should do upon entry into the function call? Callee save the s registers Q-iv: What is the value of register number 2 (i.e ) after completes (assuming there were no other function calls, no interrupts, no context switches, etc.) 33. Register 2 = v0. It should not have changed. (different answer if you assume printf returns value) Q-v: Does the return address register (\$ra) need to be saved on the stack for this program? Justify your answer. (Assume () does not return). No if no other procedures are called.

4 Part C: Procedures with Callee Saving (old exam question): Assume you have the following C code: int (void) { int x = 10; # x maps to \$s1 int y = 20; # y maps to \$s2 int z = 30; # z maps to \$s3 int a; # a maps to \$t0 int b; # b maps to \$t1 int c; # c maps to \$t2 c = x + y; a = multiply(x, z); b = c + x; int multiply(int a, int b) { int q; # q maps to \$t0 int z; # z maps to \$t1 q = add(); z = a*b; return z; int add() { int m = 5; # m maps to \$t4 int n = 4; # n maps to \$t5 int y; y = a + b; return y; Assuming the MIPS calling convention, answer questions A-E. Note no assembly code/machine instructions are required in your answers; simple explanations are sufficient.

5 Q-i: What, if anything must () do before calling multiply? - Save \$t2 to stack, needed upon return. - Also, copy \$s1 to \$a0 and copy \$s3 to \$a1 Q-ii: Does multiply need to save anything to the stack? If so, what? - \$31 - The s registers associated with () - The argument registers passed into multiply before calling add() Q-iii: Assume that multiply returns its value to () per the MIPS register convention. What machine instructions might we see at to completely facilitate the function return? - We have to copy the value in \$t1 to \$2. - We would call a jal instruction - We would adjust the stack pointer, restored saved registers. Q-iv: What line of code should the return address register point to at? - b = c + x Other answers were considered correct based on stated assumptions. Q-v: What line of code should the return address register point to at? - b = c + x Other answers were considered correct based on stated assumptions.

8 Part E: Nested Function Calls int (void) { foo1() { foo2() { i = 5; # i = \$16 a = 17; # a = \$16 x = 25; # x = \$16 j = 6; # j = \$17 b = 24; # b = \$17 y = 12; # y = \$17 k = foo1(); j = j + 1; foo2(); Let s consider how we might use the stack to support these nested calls. Question: How do we make sure that data for i, j (\$16, \$17) is preserved here? Answer: Use a stack. By convention, the stack grows up: Low Memory Address (0)! \$sp! Let s look at (): - Assume we want to save \$17 and \$16 o (we ll use the stack pointer) - Also, anything else we want to save? o \$31 if nested calls. - How? o subi \$sp, \$sp, 12 # make space for 3 data words High Memory Address (N)! o Example: assume \$sp = 100, therefore \$sp = = 88 - Then, store results: \$sp new! 88! o sw 8(\$sp), \$16 # address: 8 + \$sp = = 96 o sw 4(\$sp), \$17 # address: 4 + \$sp = = 92 o sw 0(\$sp), \$31 # address: 0 + \$sp = = 88 92! 96! \$sp old! 100! Now, in Foo1() assume A and B are needed past Foo2() how do we save them? - We can do the same as before o Update \$sp by 12 and save Similarly, can do the same for Foo2()

9 Now, assume that we are returning from Foo1() to (). What do we do? - The stack pointer should equal the value before the Foo1() call (i.e. 88) lw \$31, 0(\$sp) # \$31 memory(0 + 88) (LIFO) lw \$17, 4(\$sp) # \$17 memory(4 + 88) lw \$16, 8(\$sp) # \$16 memory(8 + 88) Finally, update \$sp: addi \$sp, \$sp, 12 (\$sp now = 100 again) Let s talk about the Frame Pointer too: (2) On function call, \$sp decremented! (3) Also a register called Frame Pointer! (1) \$sp! (frame pointer) points to the beginning of the stack (ish) or the first word in frame of a procedure Why use a? - Stack used to store variables local to procedure that may not fit into registers - \$sp can change during procedure (e.g. as just seen) o Results in different offsets that may make procedure harder to understand - is stable base register for local memory references For example: \$sp (in foo1() = 88)! \$16! \$17! (might be here)! \$31! generally > \$sp! More Generally:! Low Memory Address (0)! \$sp! Saved saved regs!! Saved \$ra,! Saved args! High Memory Address (N)! -"Therefore procedure might reference extra function argument as 0()! -"What if 2 saved arguments? What next?! -"With this convention: lw \$t0, 4()! Because \$sp can change dynamically, often easier/intuitive to reference extra arguments via stable although can use \$sp with a little extra math

10 Part F: Recursive Function Calls 2 (n<1 check)! 1 (immediately inside function)! 4 (put "1# in return register)! 5 (return)! 3 (recursive function call)! 6 (multiply function values)! Let s consider how we might use the stack to support these nested calls. We ll also make use of the frame pointer (). Code Section # Address Label MIPS Instruction Comments 1 0 Fact: subi \$sp, \$sp, 12 Make room for 3 pieces of data on the stack;, \$sp, and 1 local argument 4 sw 8(\$sp), \$ra If \$sp = 88, M(88 + 8) value of \$ra 8 sw 4(\$sp), If \$sp = 88, M(88 + 4) value of 12 subi,, 12 Update the frame pointer 2 16 bgtz \$a0, L2 If N > 0 (i.e. not < 1) we re not done we assume N is in \$a addi \$v0, \$0, 1 We eventually finish and want to return 1, therefore put 1 in return register 24 j L1 Jump Jump to to return return code code L2: L2: sw sw \$a0, \$a0, 0() 0() Save Save argument N to N to stack stack (we!ll (we ll need need it when it when we we return) return) subi subi \$a0, \$a0, \$a0, \$a0, 1 1 Decrement N (N N (N = N = N 1), 1), put put result result in in \$a0 \$a jal jal Fact Fact Call Call Factorial() again again lw lw \$t0, \$t0, 0(\$f0) 0(\$f0) Load Load N (saved N at at *** *** to to stack) stack) mult mult \$v0, \$v0, \$v0, \$v0, \$t0 \$t0 Store Store result result in in \$v0 \$v L1: L1: lw lw \$ra, \$ra, 8(\$sp) 8(\$sp) Restore return return address lw lw,, 4(\$sp) 4(\$sp) Restore frame frame pointer pointer addi addi \$sp, \$sp, \$sp, \$sp, Pop Pop stack stack jr \$ra jr \$ra Return Return from from factorial

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

### 4.2: MIPS function calls

4.2: MIPS function calls Topics: Nested function calls: poly() and pow() Saving the return address (\$31) Saving temporary registers Looking at activation records on the stack Introduction: In CSc 256 lectures,

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

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

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

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

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

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

### Subroutines and Stack Usage on the MicroBlaze. ECE 3534 Microprocessor System Design

Subroutines and Stack Usage on the MicroBlaze ECE 3534 Microprocessor System Design 1 MicroBlaze Subroutines Same idea as a C/C++ function There s no call instruction Instead, branch and link Example:

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

### Implementing Functions at the Machine Level

Subroutines/Functions Implementing Functions at the Machine Level A subroutine is a program fragment that... Resides in user space (i.e, not in OS) Performs a well-defined task Is invoked (called) by a

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

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

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

### Function Calls. Tom Kelliher, CS 220. Oct. 24, SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how.

Function Calls Tom Kelliher, CS 220 Oct. 24, 2011 1 Administrivia Announcements Assignment SPIM programs due Wednesday. Refer to homework handout for what to turn in, and how. From Last Time Outline 1.

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

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

EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 C functions main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } What information must compiler/programmer keep

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

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

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

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

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

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

### CSE 220: System Fundamentals I Unit 14: MIPS Assembly: Multi-dimensional Arrays. Kevin McDonnell Stony Brook University CSE 220

CSE 220: System Fundamentals I Unit 14: MIPS Assembly: Multi-dimensional Arrays 1 Memory Alignment Perhaps at some point in your MIPS assembly programming you tried to perform a lw and received an error

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

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

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

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

### Calling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Calling Conventions See P&H 2.8 and 2.12 Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Goals for Today Review: Calling Conventions call a routine (i.e. transfer control to

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

### CSc 520 Principles of Programming Languages. Questions. rocedures as Control Abstractions... 30: Procedures Introduction

Procedures as Control Abstractions CSc 520 Principles of Programming Languages 30: Procedures Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona

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

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

NET3001 Advanced Assembly Arrays and Indexing supposed we have an array of 16 bytes at 0x0800.0100 write a program that determines if the array contains the byte '0x12' set r0=1 if the byte is found plan:

### Subprograms, Subroutines, and Functions

Subprograms, Subroutines, and Functions Subprograms are also called subroutines, functions, procedures and methods. A function is just a subprogram that returns a value; say Y = SIN(X). In general, the

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

### Machine Organization & Assembly Language

Name: CSE 378 Winter 29 Machine Organization & Assembly Language Midterm Exam Solution your answers on these pages. itional pages may be attached (with staple) if necessary. Please ensure that your answers

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

### MIPS Procedure Calls - Review

MIPS Stacks and Subroutine Calls Cptr280 Dr Curtis Nelson MIPS Procedure Calls - Review When making a procedure or function call, it is necessary to: Place parameters you wish to pass where they can be

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

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

### 6.001 Recitation 23: Register Machines and Stack Frames

6.001 Recitation 23: Register achines and Stack Frames RI: Gerald Dalley, dalleyg@mit.edu, 8 ay 2007 http://people.csail.mit.edu/dalleyg/6.001/sp2007/ iscellany apply: See the IT Scheme documentation for

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

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

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

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

### Computer Engineering Fall Semester, 2011

Computer Engineering 9859 Fall Semester, 2011 1 What will we do in this course? We will look at the design of an instruction set for a simple processor. The processor is based on a real processor, the

### CSC 2400: Computing Systems. X86 Assembly: Function Calls"

CSC 24: Computing Systems X86 Assembly: Function Calls" 1 Lecture Goals! Challenges of supporting functions" Providing information for the called function" Function arguments and local variables" Allowing

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

### Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu

Assembly Programming (III) Lecturer: Sri Parameswaran Notes by: Annie Guo Dr. Hui Wu 1 Lecture overview Stack and stack operations Functions and function calls Calling conventions 2 Stack What is stack?

### Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

s and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements Homework Set #2 due Friday at 11 am - extension Program Assignment #1 due Tuesday Feb. 15 at 11 am - note extension

### ECE251: Tuesday September 12

ECE251: Tuesday September 12 Finish Branch related instructions Stack Subroutines Note: Lab 3 is a 2 week lab, starting this week and covers the Stack and Subroutines. Labs: Lab #2 is due this week. Lab

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

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

### Runtime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V.

Runtime management CS3300 - Compiler Design Runtime management V Krishna Nandivada IIT Madras Copyright c 2001 by Antony L Hosking Permission to make digital or hard copies of part or all of this work

### CSC 2400: Computing Systems. X86 Assembly: Function Calls

CSC 24: Computing Systems X86 Assembly: Function Calls 1 Lecture Goals Challenges of supporting functions Providing information for the called function Function arguments and local variables Allowing the

### Stack Discipline Jan. 19, 2018

15-410 An Experience Like No Other Discipline Jan. 19, 2018 Dave Eckhardt Brian Railing Slides originally stolen from 15-213 1 15-410, S 18 Synchronization Registration The wait list will probably be done

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

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