Winter 2002 MID-SESSION TEST Friday, March 1 6:30 to 8:00pm



Similar documents
Reduced Instruction Set Computer (RISC)

COMP 303 MIPS Processor Design Project 4: MIPS Processor Due Date: 11 December :59

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Typy danych. Data types: Literals:

Lecture Outline. Stack machines The MIPS assembly language. Code Generation (I)

MIPS Assembly Code Layout

More MIPS: Recursion. Computer Science 104 Lecture 9

Assembly Language Programming

Translating C code to MIPS

Computer Systems Architecture

Introduction to MIPS Assembly Programming

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

PCSpim Tutorial. Nathan Goulding-Hotta v0.1

Instruction Set Architecture. or How to talk to computers if you aren t in Star Trek

Review: MIPS Addressing Modes/Instruction Formats

The Operating System and the Kernel

MIPS Assembler and Simulator

5 MIPS Assembly Language

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Instruction Set Architecture

Introduction to MIPS Programming with Mars

Lecture 8: Binary Multiplication & Division

Instruction Set Architecture (ISA) Design. Classification Categories

Compilers I - Chapter 4: Generating Better Code

Lab Work 2. MIPS assembly and introduction to PCSpim

Computer Organization and Components

Chapter 7D The Java Virtual Machine

Design of Pipelined MIPS Processor. Sept. 24 & 26, 1997

CSE 141 Introduction to Computer Architecture Summer Session I, Lecture 1 Introduction. Pramod V. Argade June 27, 2005

COMPUTER ORGANIZATION ARCHITECTURES FOR EMBEDDED COMPUTING

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Figure 1: Graphical example of a mergesort 1.

Design of Digital Circuits (SS16)

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

CS 241 Data Organization Coding Standards

Intel 8086 architecture

CS 61C: Great Ideas in Computer Architecture Finite State Machines. Machine Interpreta4on

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

csci 210: Data Structures Recursion

CS352H: Computer Systems Architecture

Q. Consider a dynamic instruction execution (an execution trace, in other words) that consists of repeats of code in this pattern:

Syscall 5. Erik Jonsson School of Engineering and Computer Science. The University of Texas at Dallas

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Slide Set 8. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

EE361: Digital Computer Organization Course Syllabus

SMIPS Processor Specification

Instruction Set Design

Parameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C

M A S S A C H U S E T T S I N S T I T U T E O F T E C H N O L O G Y DEPARTMENT OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Modbus RTU Communications RX/WX and MRX/MWX

Chapter 5 Instructor's Manual

CSI 333 Lecture 1 Number Systems

2.2: Bitwise Logical Operations

Informatica e Sistemi in Tempo Reale

Instruction Set Architecture (ISA)

PROBLEMS (Cap. 4 - Istruzioni macchina)

TETRIX Add-On Extensions. Encoder Programming Guide (ROBOTC )

EECS 427 RISC PROCESSOR

CS2210: Compiler Construction. Runtime Environment

Supporting Data Set Joins in BIRT

C Compiler Targeting the Java Virtual Machine

CSC 2405: Computer Systems II

Analysis of Binary Search algorithm and Selection Sort algorithm

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Sources: On the Web: Slides will be available on:

Recursion. Slides. Programming in C++ Computer Science Dept Va Tech Aug., Barnette ND, McQuain WD

2) Write in detail the issues in the design of code generator.

Chapter 2 Topics. 2.1 Classification of Computers & Instructions 2.2 Classes of Instruction Sets 2.3 Informal Description of Simple RISC Computer, SRC

Analysis of a Search Algorithm

Regular Languages and Finite Automata

Part 1 Foundations of object orientation

1 Description of The Simpletron

Recursion vs. Iteration Eliminating Recursion

Solutions. Solution The values of the signals are as follows:

Fall 2006 CS/ECE 333 Lab 1 Programming in SRC Assembly

Computer organization

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

MECH 896 Professional Development for MEng Students. Homework Discussion. Scheduling Overview. Winter 2015: Lecture #5 Project Time Management

1 The Java Virtual Machine

The AVR Microcontroller and C Compiler Co-Design Dr. Gaute Myklebust ATMEL Corporation ATMEL Development Center, Trondheim, Norway

6. Control Structures

Bi-8: Introduction to Molecular Biology by Prof. Angela Stathopoulos

Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?

The Little Man Computer

J a v a Quiz (Unit 3, Test 0 Practice)

The programming language C. sws1 1

Stacks. Linear data structures

Central Processing Unit Simulation Version v2.5 (July 2005) Charles André University Nice-Sophia Antipolis

X86-64 Architecture Guide

How To Write An Array In A Microsoft Zil

EC 362 Problem Set #2

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

EXERCISES FROM HULL S BOOK

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

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 2002 MID-SESSION TEST Friday, March 1 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 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 14 marks) The function proc_c is defined in the following C translation unit: int proc_a(int j, int k); int * proc_b(int *p, int *q); int proc_c(int x, int y, int *z) int a, b; a = proc_a(y, *z); b = *proc_b(&a, &x); return a * (b + y + *z); Part a. (3 marks) For each of the local variables a and b state whether the variable should be in a register or on the stack. Briefly give reasons to support your answer. Part b. (11 marks) Translate the definition of the function proc_c 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. Assume the following for integer multiplication: The 64-bit product of two 32-bit operands is computed, then bits 31 0 of the product are copied into the register or memory word corresponding to the result. PROBLEM 2 (16 marks) Here is a C program: void f1(int *a, int *b, int n); int f2(int k); int aaa[3] = 0x100, 0x200, 0x300 ; int main(void) int bbb[3]; int *p; for (p = bbb; p < bbb + 3; p++) *p = 0x150; f1(aaa, bbb, 3); return 0; void f1(int *a, int *b, int n) int i; for (i = 0; i < n; i++) b[i] += f2(i) + a[i]; int f2(int k) int x; x = k + k; /* point one */ return x + k; PAGE 2 OF 5

Below is a correct translation of that C program 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. (The listing starts on this page and continues on the next page.).data aaa aaa:.word 0x100, 0x200, 0x300 main: loop1: quit1:.text main addiu $sp, $sp, -20 sw $ra, 16($sp) sw $s0, 12($sp) addiu $s0, $sp, 0 addiu $t0, $sp, 12 # $t0 = bbb + 3 addiu $t1, $zero, 0x150 sltu $t2, $s0, $t0 beq $t2, $zero, quit1 sw $t1, ($s0) addiu $s0, $s0, 4 j loop1 la $a0, aaa addiu $a1, $sp, 0 addiu $a2, $zero, 3 jal f1 addiu $v0, $zero, 0 lw $s0, 12($sp) lw $ra, 16($sp) addiu $sp, $sp, 20 f1: loop2: f1 addiu $sp, $sp, -20 sw $a2, 16($sp) sw $a1, 12($sp) sw $a0, 8($sp) sw $ra, 4($sp) sw $s0, 0($sp) addiu $s0, $zero, 0 lw $t0, 16($sp) slt $t1, $s0, $t0 beq $t1, $zero, quit2 addu $a0, $s0, $zero jal f2 addu $t2, $s0, $s0 addu $t2, $t2, $t2 # $t2 = 4*i lw $t3, 12($sp) addu $t3, $t3, $t2 lw $t4, 8($sp) PAGE 3 OF 5

quit2: f2: addu $t4, $t4, $t2 lw $t5, ($t3) lw $t6, ($t4) addu $t7, $v0, $t5 addu $t6, $t7, $t6 sw $t6, ($t3) addiu $s0, $s0, 1 j loop2 lw $s0, 0($sp) lw $ra, 4($sp) addiu $sp, $sp, 20 f2 addiu $sp, $sp, -4 sw $s0, 0($sp) addu $s0, $a0, $s0 # point one addu $v0, $s0, $a0 lw $s0, 0($sp) addiu $sp, $sp, 4 What To Do: Consider the third time 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; list the contents of registers $a0, $s0, $sp, and $ra. Show the contents of the stack slots and registers as numbers. Assume the following: When main is called, $ra contains 0x0040_0018, $s0 contains 0, and $sp contains 0x7fff_ffcc. The address of aaa[0] is 0x1001_0000. The address of the instruction jal f1 is 0x0040_0058. The address of the instruction labeled loop2 is 0x0040_008c. PROBLEM 3 (total of 11 marks) Part a. (4 marks) Given the following values in MIPS general purpose registers: $t1 = 0x8000_0000, $t2 = 0x0000_0001 What values are in registers $t3 and $t4 after the following instructions are executed: slt $t3, $t2, $t1 subu $t4, $t1, $t2 PAGE 4 OF 5

Show or explain how you obtained your answers. Part b. (2 marks) In the subu instruction of part a, did overflow occur? Briefly explain how you obtained your answer. Part c. (2 marks) Two (of many) ways to load a 32-bit constant into a register are: to use SPIM instructions lui and addiu; to use SPIM instructions lui and ori. Suppose an assembly language wants to put 0x0001_8000 into $t0. Which of the above ways is preferable? Why? Part d. (3 marks) Write a sequence of SPIM instructions (not a complete procedure) to copy bits 22 16 of register $s0 to bits 8 2 of register $s1 while making all other bits of $s1 equal to zero. Your instructions should not modify the contents of $s0. Modification of some t-registers contents is allowed (but not required). PROBLEM 4 (total of 18 marks) Part a. (12 marks) Consider the following C function, which returns the index of a maximum value among a[0], a[1],... a[n-1]: int index_of_max(const int *a, int n) const int *p; const int *q; int max; const int *x; p = a + 1; q = a; max = *a; x = a + n; while (p < x) if (*p > max) max = *p; q = p; p++; return q - a; 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 p, $s1 for q, $s2 for max, and $s3 for x. Part b. (6 marks) Consider the following C function: void put_zero(char *a, int n) int i; for (i = n - 1; i >= 0; i--) a[i] = 0; 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 i. PAGE 5 OF 5