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.

Similar documents
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.

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

#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 2006 FINAL EXAMINATION Auxiliary Gymnasium Tuesday, April 18 7:00pm to 10:00pm

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

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

Winter 2002 FINAL EXAMINATION

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

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

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

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

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

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

MIPS Assembly Programming

Computer Architecture I Midterm I

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

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

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

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

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

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

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

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

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

ECE331: Hardware Organization and Design

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

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

MIPS Instruction Reference

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

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

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

CS61c MIDTERM EXAM: 3/17/99

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

Assembly Programming

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

ENCM 369 Winter 2015 Lab 6 for the Week of March 2

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

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

2) Using the same instruction set for the TinyProc2, convert the following hex values to assembly language: x0f

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

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

CSE A215 Assembly Language Programming for Engineers

CS 61c: Great Ideas in Computer Architecture

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 22 September Your Name (please print clearly) Signed.

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

CPS311 - COMPUTER ORGANIZATION. A bit of history

CSEE W3827 Fundamentals of Computer Systems Homework Assignment 3 Solutions

Reduced Instruction Set Computer (RISC)

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

MIPS Assembly Language. Today s Lecture

Reduced Instruction Set Computer (RISC)

Compiling Techniques

Computer Architecture. The Language of the Machine

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

MIPS Functions and the Runtime Stack

Lecture 6: Assembly Programs

Examples of branch instructions

CS3350B Computer Architecture

CSc 256 Midterm (green) Fall 2018

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

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

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

The MIPS Instruction Set Architecture

MIPS Reference Guide

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

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

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

Flow of Control -- Conditional branch instructions

CPSC 330 Computer Organization

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

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

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

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam One 19 September 2012

MIPS Assembly: Practice Questions for Midterm 1 Saving to and Loading from Memory CS 64: Computer Organization and Design Logic Lecture #6

ECE 30 Introduction to Computer Engineering

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

ECE468 Computer Organization & Architecture. MIPS Instruction Set Architecture

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

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

Slide Set 1 (corrected)

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

MIPS Instruction Set

CDA3100 Midterm Exam, Summer 2013

SPIM Instruction Set

F. Appendix 6 MIPS Instruction Reference

SPIM Procedure Calls

ECE 15B Computer Organization Spring 2010

UCB CS61C : Machine Structures

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

CS222: Dr. A. Sahu. Indian Institute of Technology Guwahati

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

Agenda. Strings: C vs. Java. Loading, Storing bytes. Support for Characters and Strings 6/29/2011

Instructions: Language of the Computer

Transcription:

University of Calgary Department of Electrical and Computer Engineering ENCM 369: Computer Organization Lecture Instructors: S. A. Norman and N. R. Bartley 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. Name (printed): Signature: Lecture section (L01 is MWF 11:00am with S. Norman, L02 is MWF 10:00am with N. Bartley): 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, U of C ID number, and lecture section 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.

ENCM 369 Winter 2012 Mid-Session Test page 2 of 8 PROBLEM 1 (12 marks) Consider the C code listed to the right. Translate the function proc1 into SPIM assembly language. Follow the usual calling conventions from lectures and labs, and use only instructions from the Midterm Instruction Subset described on the Reference Material page. int helper(int x, int *p); int proc1(int *a, const int *b, int n) int k, s, v2; s = 0; for (k = 0; k < n; k++) s += helper(b[k], &v2); a[k] = v2; return s;

ENCM 369 Winter 2012 Mid-Session Test page 3 of 8 PROBLEM 2 (9 marks) Consider the C code listed to the right. Translate the function insert_spaces into SPIM assembly language. Follow the usual calling conventions from lectures and labs, and use only instructions from the Midterm Instruction Subset described on the Reference Material page. Note: The SPIM assembler will accept (the character constant for a space) as an operand in instructions such as addi and ori. void insert_spaces(char *dest, const char *src) if (*src!= \0 ) *dest = *src; dest++; while (*(src + 1)!= \0 ) *dest = ; *(dest + 1) = *(src + 1); dest += 2; src++; *dest = \0 ;

ENCM 369 Winter 2012 Mid-Session Test page 4 of 8 PROBLEM 3 (11 marks) The SPIM program below on the right is a correct translation of the C program below on the left, using the usual procedure calling conventions presented in ENCM 369. The SPIM program reaches point one twice. For the second of those times fill in both the diagram of the stack and the table of register values, found near the bottom of this page. Show all register and stack slot contents as numbers, using either base ten or hexadecimal notation as convenient. Note that the program will not actually use all of the stack slots shown in the diagram. Assume the following register contents when main starts: $ra = 0x0040_0018; $sp = 0x7fff_fd9c; $s0 = 0x50; $s1 = 0x51. Also assume that the address of the first instruction of main is 0x0040_0024, the address of the first instruction of foo is 0x0040_0080, and the address of the first instruction of bar is 0x0040_0098. void foo(int *q); void bar(int i, int *p); int main(void) int a, b, c; a = 31; b = 47; c = 52; bar(100, &b); bar(200, &c); a += c - b; return 0; void foo(int *q) *q = *q / 10;.text.globl main main: addiu $sp, $sp, -16 sw $ra, 12($sp) sw $s0, 8($sp) addiu $s0, $zero, 31 addiu $t0, $zero, 47 sw $t0, 0($sp) addiu $t1, $zero, 52 sw $t1, 4($sp) addiu $a0, $zero, 100 addiu $a1, $sp, 0 jal bar addiu $a0, $zero, 200 addiu $a1, $sp, 4 jal bar lw $t2, 4($sp) lw $t3, 0($sp) subu $t4, $t2, $t3 addu $s0, $s0, $t4 addu $v0, $zero, $zero lw $s0, 8($sp) lw $ra, 12($sp) addiu $sp, $sp, 16 jr $ra.globl foo foo: lw $t5, ($a0) addiu $t6, $zero, 10 div $t5, $t6 mflo $t7 sw $t7, ($a0) # POINT ONE void bar(int i, int *p) foo(p); *p += i; high addr esses data saved before main was called jr $ra.globl bar bar: addiu $sp, $sp, -12 sw $ra, 8($sp) sw $s1, 4($sp) sw $s0, 0($sp) addu $s0, $a0, $zero addu $s1, $a1, $zero addu $a0, $s1, $zero jal foo lw $t8, ($s1) addu $t9, $t8, $s0 sw $t9, ($s1) lw $s0, 0($sp) lw $s1, 4($sp) lw $ra, 8($sp) addiu $sp, $sp, 12 jr $ra register $a0 $ra $sp $t5 value

ENCM 369 Winter 2012 Mid-Session Test page 5 of 8 PROBLEM 4 (total of 11 marks) In this problem, you are asked to translate sequences of one or more C statements into sequences of one or more SPIM instructions, not complete SPIM procedures. Use only instructions from the Midterm Instruction Subset. Use as many t-registers as you wish for intermediate values. Example. (No marks.) GPR $s0 is used for x, of type int. C code SPIM instruction(s) x = 42; addi $s0, $zero, 42 Part a. (2 marks.) $a0 is used for p, of type int*, and $s1 is used for i, of type int. C code SPIM instruction(s) p[3] += i; Part b. (4 marks.) $s0 is used for j and $s1 is used for k, both of type int. $s2 is used for p, of type int*; The function func has an argument of type int and returns an int. C code if (p == 0 *p < 32) j++; else j += func(*p); k++; SPIM instruction(s) Part c. (3 marks.) An array of 5 ints named x is allocated within a stack frame. The address of x[0] is 8($sp). $s0 is used for the int variable k. The function swap takes two arguments of type int* and does not return a value. C code swap(&x[0], &x[k]); SPIM instruction(s) Part d. (2 marks.) $s3 is used for m, and $s4 for n, both of type unsigned int. C code SPIM instruction(s) m = n % 99;

ENCM 369 Winter 2012 Mid-Session Test page 6 of 8 PROBLEM 5 (total of 10 marks). The SPIM program below on the right is a correct translation of the C program below on the left, assuming that the address of pmax is 0x1001_0000. The program searches the array arr for its largest element, and leaves the address of that element in the variable pmax. int *pmax = 0; int arr[6] = 10, 11, 12, 13, 99, 15 ; int main(void) int *p; int *guard; int max; pmax = arr; p = arr; max = *p; guard = p + 6; p++; while (p!= guard) if (max < *p) max = *p; pmax = p; p++; /* POINT ONE */ return 0; Part a. (1 mark.) List the two assembly language instructions that correspond to the C statement p = arr;.data.globl pmax pmax:.word 0.globl arr arr:.word 10, 11, 12, 13, 99, 15.text.globl main main: lui $t0, 0x1001 ori $t0, 0x0004 lui $t1, 0x1001 sw $t0, 0($t1) lui $t7, 0x1001 ori $t7, 0x0004 lw $t9, ($t7) addiu $t8, $t7, 24 addiu $t7, $t7, 4 L1: beq $t7, $t8, L2 lw $t2, ($t7) slt $t3, $t9, $t2 beq $t3, $zero, L3 addu $t9, $zero, $t2 lui $t4, 0x1001 sw $t7, ($t4) L3: addiu $t7, $t7, 4 j L1 L2: # POINT ONE addu jr $v0, $zero, $zero $ra Part b. (1 mark.) List the two assembly language instructions that correspond to the C statement pmax = p; Part c. (8 marks.) Fill in the following tables to show contents of registers and memory when the SPIM program reaches point one. All memory words and register values must be given as numbers, but for each number you can choose base ten or hexadecimal format, whichever is more convenient. memory address 0x1001_0000 0x1001_0004 0x1001_0008 0x1001_000c 0x1001_0010 0x1001_0014 0x1001_0018 memory word value register $t2 $t3 $t7 $t8 $t9 value

ENCM 369 Winter 2012 Mid-Session Test page 7 of 8 PROBLEM 6 (total of 13 marks) Part a. (3 marks.) Suppose $t0 contains 0x5c00_0000, $t1 contains 0xa400_0000, and the instruction add $t2, $t0, $t1 is run. What is the 32-bit addition result, expressed in base sixteen? Will there be an exception caused by this instruction? Briefly explain why there will or will not be an exception. Part b. (3 marks.) Suppose an 8-bit subtraction circuit is used to compute a b, where a = 0x90 and b = 0x22. Expressing your answer in base two, what will be the 8-bit subtraction result? Is there overflow in this computation? Is there wraparound? Part c. (3 marks.) Suppose $t0 contains 0xab2a_bcde. What will be in $t3 after these three instructions are run? sll $t1, $t0, 8 andi $t2, $t1, 0x3f00 ori $t3, $t2, 0x8009 Express your answer in base sixteen, and show how you obtained your answer. Part d. (2 marks.) Suppose $t0 contains 0x8000_0000 and $t1 contains 0x0000_1000. Suppose mult $t0, $t1 is executed. What will be the contents of the Hi and Lo registers after this instruction is executed? (Hint: 0x1000 is 2 12.) Part e. (2 marks.) Suppose a student is trying to write assembly language code for a C procedure in which some variables are ints and others are doubles. In particular, k is an int in $s0, and s and t are doubles in floating-point registers $f20 and $f22. The student tries to code s = k - t as sub.d $f20, $s0, $f22. Explain briefly why that idea is seriously incorrect. (Since we have just started to study floating-point programming, you do not have to give correct code assembly language code.)

ENCM 369 Winter 2012 Mid-Session Test page 8 of 8 PROBLEM 7 (total of 8 marks) Part a. (4 marks.) The tools in the toolchain used in C programming are: assembler, compiler, linker, preprocessor. Note that the order of this list is alphabetical and might not reflect the order in which the tools are used. The kinds of files these tools work with are: assembly language files,.c files, executable files, header files, library machine code files, object files, translation units. This list is also alphabetical and might not reflect the order in which these files are created. Fill in the following table. Note that some tools may have more than one kind of input file, but each tool has only one kind of output file. input file(s) tool output file assembler compiler linker preprocessor Part b. (4 marks.) As presented in a recent lecture, an IEEE 754 32-bit floating-point number is organized as follows: bit 31 is the sign bit, bits 30 23 are used for the biased exponent, and the other 23 bits are for the fraction part of the significand. The bias in the exponent is 01111111 two = 127 ten. Use the above information to determine what base ten number is represented by the 32-bit IEEE floating-point bit pattern 0x41980000. Show the work needed to obtain your answer. MARKS: The space below will be used to record your marks for each question and your overall test mark. Please put your name, signature, and U of C ID number in the appropriate boxes. Name (printed): Signature: Problem Mark 1 / 12 2 / 9 3 / 11 U of Calgary ID number: 4 / 11 5 / 10 6 / 13 Lecture Section (L01 is 11:00am, L02 is 10:00am): 7 / 8 TOTAL / 74