Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm

Similar documents
Winter 2012 MID-SESSION TEST Tuesday, March 6 6:30pm to 8:15pm. Please do not write your U of C ID number on this cover page.

Winter 2017 MIDTERM TEST #1 Wednesday, February 8 7:00pm to 8:30pm. Please do not write your U of C ID number on this cover page.

#1 #2 with corrections Monday, March 12 7:00pm to 8:30pm. Please do not write your U of C ID number on this cover page.

Winter 2002 FINAL EXAMINATION

Winter 2009 FINAL EXAMINATION Location: Engineering A Block, Room 201 Saturday, April 25 noon to 3:00pm

Winter 2006 FINAL EXAMINATION Auxiliary Gymnasium Tuesday, April 18 7:00pm to 10:00pm

University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Instructor: Steve Norman

Computer Architecture I Midterm I

ENCM 369 Winter 2017 Lab 3 for the Week of January 30

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

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

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 21 October 2016

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

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

Chapter 2. Instructions:

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Lecture 5: Procedure Calls

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

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

MIPS Assembly Programming

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

MIPS Functions and the Runtime Stack

CS61C Machine Structures. Lecture 12 - MIPS Procedures II & Logical Ops. 2/13/2006 John Wawrzynek. www-inst.eecs.berkeley.

Chapter 3. Instructions:

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

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam One 4 February Your Name (please print clearly)

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

University of California College of Engineering Computer Science Division -EECS. CS 152 Midterm I

CS61c MIDTERM EXAM: 3/17/99

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

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

University of Calgary Department of Electrical and Computer Engineering ENCM 335 Instructor: Steve Norman

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

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Examples of branch instructions

CS 61c: Great Ideas in Computer Architecture

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

MIPS Assembly Language Programming

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

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Three 10 April 2013

Flow of Control -- Conditional branch instructions

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

MIPS function continued

CS 61c: Great Ideas in Computer Architecture

ENCM 369 Winter 2018 Lab 9 for the Week of March 19

CSE Lecture In Class Example Handout

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

ECE331: Hardware Organization and Design

MIPS Assembly Language Programming

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 5 2/22/2018

University of California at Santa Barbara. ECE 154A Introduction to Computer Architecture. Quiz #1. October 30 th, Name (Last, First)

CPS311 - COMPUTER ORGANIZATION. A bit of history

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Processor design - MIPS

CSc 256 Midterm (green) Fall 2018

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

CS3350B Computer Architecture

The MIPS Instruction Set Architecture

Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: MIPS Programming

University of Calgary Department of Electrical and Computer Engineering ENCM 339 Lecture Section 01 Instructor: Steve Norman

Programming the processor

ECE/CS 314 Fall 2003 Homework 2 Solutions. Question 1

ECE 473 Computer Architecture and Organization Project: Design of a Five Stage Pipelined MIPS-like Processor Project Team TWO Objectives

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

MIPS Assembly Language. Today s Lecture

CSE Lecture In Class Example Handout

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

Lecture 6: Assembly Programs

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

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 9 December 2015

CS61C : Machine Structures

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Slide Set 1 (corrected)

From Code to Program: CALL Con'nued (Linking, and Loading)

ECE 15B COMPUTER ORGANIZATION

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

Signature: 1. (10 points) Basic Microcontroller Concepts

EE 361 University of Hawaii Fall

CS 110 Computer Architecture Lecture 6: More MIPS, MIPS Functions

SPIM Instruction Set

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions

SPIM & MIPS. Department of Information and Management. Computer Organization and Structure 年 9 月 29 日星期 一

CDA3100 Midterm Exam, Summer 2013

S Computer Architecture. Computer architecture assignment E1 A subroutine, which searches for given byte pattern from an byte array.

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

bits 5..0 the sub-function of opcode 0, 32 for the add instruction

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

MIPS Reference Guide

CSc 256 Midterm 1 Fall 2011

CS222: MIPS Instruction Set

Transcription:

University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Instructors: Dr. S. A. Norman (L01) and Dr. S. Yanushkevich (L02) Winter 2003 MID-SESSION TEST Monday, March 10 6:30 to 8:00pm Notes to Winter 2005 ENCM 369 Students This handout contains the questions from an old midterm. Spaces for answers have been removed in order to save paper in printing. General Instructions Marks will be recorded on the last page of this question paper. When you are told to start the test, the first thing you should do is to put your name, signature and U of C ID number in the appropriate spaces at the bottom of the last page. You may not use electronic calculators or computers during the test. The test is closed-book. You may not refer to books or notes during the test, with one exception: you may refer to the Reference Material page that accompanies this test paper. You are not required to add comments to assembly language code you write, but you are strongly encouraged to do so, because writing good comments will improve the probability that your code is correct and will help you to check your code after it is finished. Some problems are relatively easy and some are relatively difficult. Go after the easy marks first. To reduce distraction to other students, you are not allowed to leave during the last ten minutes of the test. Write all answers on the question paper and hand in the question paper when you are done. Please print or write your answers legibly. What cannot be read cannot be marked. If you write anything you do not want marked, put a large X through it and write rough work beside it. You may use the backs of pages for rough work. PAGE 1 OF 5

PROBLEM 1 (total of 15 marks) The function f3 is defined in the following C translation unit: int f1(int x, int y); int *f2(int *d, int *e, int f); int f3(int p, int q, int *r) int w1, w2; w2 = q - 15; w1 = f1(p, *r); w2 += *f2(&w1, r, w1); return (w2 + p + q) * 8; Part a. (3 marks) For each of the local variables w1 and w2 state whether the variable should be in a register or on the stack. Briefly give reasons to support your answer. Part b. (12 marks) Translate the definition of the function f3 into SPIM assembly language. Follow the calling conventions used in lectures and labs, and use only instructions from the Midterm Instruction Subset described on the Reference Material page. PROBLEM 2 (16 marks) Below is a partial listing of a C program. (Definitions of func3 and func4 are omitted to save space.) void func1(char *p, int n, int c); int func2(int m); void func3(char *p); void func4(int a); int main(void) int j = 12; j += func2(6); func4(j); return 0; void func1(char *p, int n, int c) int i; for (i = 0; i < n; i++) p[i] = c; p[n] = \0 ; /* point one */ int func2(int m) char s[8]; int r; if (m >= 8) r = 7; func1(s, 7, x ); PAGE 2 OF 5

else r = m; func1(s, m, y ); func3(s); return r; Below is a correct translation of the C code into SPIM assembly language. Note that it follows all calling conventions used in lectures and labs, and that each procedure uses $s0 as a local variable. main: func1: for: quit:.globl main addiu $sp, $sp, -8 sw $ra, 4($sp) sw $s0, 0($sp) addiu $s0, $zero, 12 addiu $a0, $zero, 6 jal func2 addu $s0, $s0, $v0 addu $a0, $s0, $zero jal func4 addu $v0, $zero, $zero lw $s0, 0($sp) lw $ra, 4($sp) addiu $sp, $sp, 8.globl func1 addiu $sp, $sp, -4 sw $s0, 0($sp) addiu $s0, $zero, 0 slt $t0, $s0, $a1 beq $t0, $zero, quit addu $t1, $a0, $s0 sb $a2, ($t1) addiu $s0, $s0, 1 j for addu $t1, $a0, $a1 sb $zero, ($t1) # point one lw $s0, 0($sp) addiu $sp, $sp, 4 func2:.globl func2 addiu $sp, $sp, -20 PAGE 3 OF 5

else: endif: sw $a0, 16($sp) sw $ra, 12($sp) sw $s0, 8($sp) lw $t0, 16($sp) slti $t1, $t0, 8 bne $t1, $zero, else addiu $s0, $zero, 7 addiu $a1, $zero, 7 addiu $a2, $zero, x jal func1 j endif addu $s0, $zero, $t0 addu $a1, $t0, $zero addiu $a2, $zero, y jal func1 jal func3 addu $v0, $s0, $zero lw $s0, 8($sp) lw $ra, 12($sp) addiu $sp, $sp, 20 What To Do: Consider the moment that the program passes through point one. For this moment in time make a diagram of the stack, clearly indicating the boundaries of each stack frame, and list the contents of the following registers: $a0, $a1, $a2, $sp, $ra, $s0, and $t1. When necessary, use this format to show bytes within a memory word, starting with the lowest-addressed byte on the left: Show the contents of the stack slots and registers as numbers. Assume the following: The characters codes for x, y, \0 are 120, 121 and 0. When main begins execution, $ra contains 0x0040_0018, $s0 contains 0, and $sp contains 0x7fff_ff00. The address of the first intruction in main is 0x0040_0024, the address of the first instruction in func1 is 0x0040_005c, and the address of the slti instruction in func2 is 0x0040_00a8. PAGE 4 OF 5

PROBLEM 3 (total of X marks) Part a. (2 marks) Consider the bit pattern 1000_0001_1100_0000_0000_0000_0000_0000. If it is interpreted as a two s-complement number, what number does it represent? Express your answer in a format similar to 2 27 + 2 22 + 2 20. Part b. (3 marks) The IEEE 754 32-bit floating-point format is as follows: bit 31 is the sign bit; bits 30 23 are the bits of the biased exponent the bias is 127; bits 22 0 are the significand bits. What does the bit pattern of part a represent if it is interpreted as an IEEE 754 number? Express your answer in a format similar to 3.25 2 57. Part c. (2 marks) Suppose $t0 contains 0x6000_0000 and $t1 contains 0x9fff_ffff. If the instruction sub $t2, $t0, $t1 is executed, will that update $t2, or will it cause an exception? Explain how you obtained your answer. Part d. (2 marks) Repeat part c, but this time assume that subu $t2, $t0, $t1 is executed instead. Part e. (2 marks) Suppose $t0 contains 0x000c_0f00. What values will be in $t1 and $t2 after the following two instructions are executed? andi $t1, $t0, 0x0700 sll $t2, $t0, 4 Part f. (2 marks) Explain why the following piece of assembly langauge can not be assembled into a single MIPS machine instruction. addiu $t0, $t0, -65540 PROBLEM 4 (12 marks) Part a. (12 marks) Consider the C function below, which returns the largest value among a[0], a[1],..., a[n-1]. Translate the function into SPIM assembly language. Follow the calling conventions used in lectures and labs, and use only instructions from the Midterm Instruction Subset described on the Reference Material page. You must allocate registers as follows: $s0 for max and $s1 for i. int max_value(int *a, int n) int max, i; max = a[n - 1]; i = n - 2; while (i >= 0) if (a[i] > max) max = a[i]; i--; return max; PAGE 5 OF 5