Introduction to Computer Systems. Exam 1. February 22, This is an open-book exam. Notes are permitted, but not computers.

Similar documents
Introduction to Computer Systems. Exam 1. February 22, Model Solution fp

You may work with a partner on this quiz; both of you must submit your answers.

CS , Fall 2004 Exam 1

CS , Fall 2001 Exam 1

Final exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Dec 20, Student's name: Student ID:

System Programming and Computer Architecture (Fall 2009)

4) C = 96 * B 5) 1 and 3 only 6) 2 and 4 only

CS , Fall 2002 Exam 1

UW CSE 351, Winter 2013 Midterm Exam

CPSC W Term 2 Problem Set #3 - Solution

COMP 210 Example Question Exam 2 (Solutions at the bottom)

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

CS , Spring 2004 Exam 1

CS 3843 Final Exam Fall 2012

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

EECS 213 Fall 2007 Midterm Exam

CS241 Computer Organization Spring Loops & Arrays

CMSC 313 Fall2009 Midterm Exam 2 Section 01 Nov 11, 2009

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS 2505 Computer Organization I

Question 4.2 2: (Solution, p 5) Suppose that the HYMN CPU begins with the following in memory. addr data (translation) LOAD 11110

Homework 0: Given: k-bit exponent, n-bit fraction Find: Exponent E, Significand M, Fraction f, Value V, Bit representation

SYSTEMS PROGRAMMING AND COMPUTER ARCHITECTURE Assignment 5: Assembly and C

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

CS , Fall 2007 Exam 1

Machine Programming 4: Structured Data

Process Layout and Function Calls

CS241 Computer Organization Spring 2015 IA

15-213/18-213, Fall 2011 Exam 1

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

Credits and Disclaimers

Assembly Language: Function Calls

Homework. In-line Assembly Code Machine Language Program Efficiency Tricks Reading PAL, pp 3-6, Practice Exam 1

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

CIS 2107 Computer Systems and Low-Level Programming Spring 2012 Final

Midterm Exam CSC February 2009

CPS104 Recitation: Assembly Programming

Assembly Language: Function Calls" Goals of this Lecture"

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

An Elegant Weapon for a More Civilized Age

Process Layout, Function Calls, and the Heap

The Hardware/Software Interface CSE351 Spring 2013

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

15-213/18-243, Spring 2011 Exam 1

Assembly Language: Function Calls" Goals of this Lecture"

Assembly Language: Function Calls. Goals of this Lecture. Function Call Problems

Intel assembly language using gcc

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Final Exam Introduction to Computer Systems. May 10, Name: Andrew User ID: Recitation Section: Model Solution fp

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Assembly III: Procedures. Jo, Heeseung

CSE351 Spring 2018, Midterm Exam April 27, 2018

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

Credits and Disclaimers

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

Computer Systems CEN591(502) Fall 2011

Final Exam. Fall Semester 2015 KAIST EE209 Programming Structures for Electrical Engineering. Name: Student ID:

Machine-Level Programming II: Control Flow

15-213/18-213, Fall 2011 Final Exam

CPEG421/621 Tutorial

Assembly Language: IA-32 Instructions

Final Exam Introduction to Computer Systems. May 3, Name: Andrew User ID: Recitation Section: This is an open-book exam.

CS61, Fall 2012 Midterm Review Section

Machine-level Programming (3)

Control flow. Condition codes Conditional and unconditional jumps Loops Switch statements

Do not turn the page until 5:10.

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS 2505 Computer Organization I

Machine Programming 2: Control flow

15-213/18-243, Fall 2010 Exam 1 - Version A

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Machine-Level Programming II: Control and Arithmetic

Instruction Set Architecture

Compiler Construction D7011E

Credits and Disclaimers

Assignment 11: functions, calling conventions, and the stack

Second Part of the Course

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

Full Name: CISC 360, Fall 2008 Example of Exam

hnp://

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Datorarkitektur, 2009 Tentamen

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

CIS 341 Midterm February 28, Name (printed): Pennkey (login id): SOLUTIONS

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Machine-Level Programming I: Introduction Jan. 30, 2001

EECS 213 Introduction to Computer Systems Dinda, Spring Homework 3. Memory and Cache

Sungkyunkwan University

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Assembly level Programming. 198:211 Computer Architecture. (recall) Von Neumann Architecture. Simplified hardware view. Lecture 10 Fall 2012

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Transcription:

15-213 Introduction to Computer Systems Exam 1 February 22, 2005 Name: Andrew User ID: Recitation Section: This is an open-book exam. Notes are permitted, but not computers. Write your answer legibly in the space provided. You have 80 minutes for this exam. Problem Max Score 1 15 2 15 3 15 4 15 5 7 6 8 Total 75 1

1. Floating Point (15 points) Consider the following function in assembly language. problem1: pushl movl flds fadds fmuls leave ret %ebp %esp, %ebp 16(%ebp) 12(%ebp) 8(%ebp) Recall that fld pushes the argument onto the floating point register stack, fadd pushes and adds, and fmul pushes and multiplies. The suffix s determines size of the operands to be 32 bits. 1. (5 points) Write out a corresponding function definition in C. 2. (1 points) Assume the standard representation of single-precision floating point numbers with 1 sign bit, k = 8 bits for the exponent, and n = 23 bits for the fractional value. What is the bias? 3. (5 points) Give the hexadecimal representation of the number 1 4. 4. (4 points) Give the representation of 0xBE000000 as a fraction. 2

2. Pointers and Functions (15 points) The following somewhat misguided code tries to optimize the exponential function on positive integers by creating an array of function pointers called table and using them if the exponent is less than 4. int exp0 (int x) { return 1; int exp1 (int x) { return x; int exp2 (int x) { return x * x; int exp3 (int x) { return x * x * x; = { &exp0, &exp1, &exp2, &exp3 ; int exp (int x, int n) { int y = 1; if (n < 4) return ; while (n > 0) { y *= x; n--; return y; 1. (5 points) Fill in the missing declaration of table and complete the return statement. 3

2. (3 points) Note the assignment of program variables to registers in the following assembly code produced by gcc for exp. We have elided some alignment instructions and the specialized expn functions. table:.long.long.long.long exp0 exp1 exp2 exp3 exp:.l11:.l6:.l14: Variable pushl movl subl movl cmpl movl movl jle testl jle %ebp %esp, %ebp $8, %esp 12(%ebp), %edx $3, %edx 8(%ebp), %ecx $1, %eax %edx, %edx decl %edx imull %ecx, %eax testl %edx, %edx jg.l11 leave ret subl $12, %esp pushl %ecx call jmp.l6 Register x n y 4

3. (3 points) Justify the use of particular registers chosen by gcc. 4. (4 points) Fill in the three missing lines of assembly code. 5

3. Structures and Alignment (15 points) Consider the following C declaration: typedef struct { unsigned short id; char* name; char andrew_id[9]; char year; int raw_score; double percent; Student; 1. (5 points) On the template below, show the layout of the Student structure. Delineate and label the areas for each component of the structure, cross-hatching the parts that are allocated but not used. Clearly mark the end of the structure. You should assume Linux alignment rules. Do not fill in the data fields; you will need them to answer the next question. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2. (3 points) Show the state of an instance of the Student structure after the following code is executed. Write in the assigned values by filling them into the assigned squares above and leave the remaining squares blank. Assume a Linux/x86 architecture and use hexadecimal format. Student jenn; jenn.id = 16; jenn.year = -2; jenn.raw_score = 513; 6

3. (5 points) Rewrite the declaration to use the minimal amount of space for the structure with the same components. You should make sure that the amount of space is minimal for both Linux and Windows alignment rules. 4. (2 points) How many bytes does your new structure require? 7

4. Optimization (15 points) Consider the following declaration of a linked list data structure in C: typedef struct LIST { struct LIST *next; int data; List; We use a next pointer of NULL to mark the end of the list, and we assume we have a function int length (List* p); to calculate the length of a non-circular linked list. You may assume all linked lists in this problem are non-circular. 1. (3 points) The function count pos1 is supposed to count the number of positive elements in the list at p and store it at k, but it has a serious bug which may cause it not to traverse the whole list. Insert one line and change one line to fix this problem. void count_pos1 (List *p, int *k) { int i; *k = 0; for (i = 0; i < length(p); i++) { if (p->data > 0) (*k)++; p = p->next; 2. (5 points) Further improve the efficiency of the corrected function from part 1 by eliminating the iteration variable i, changing it to a iteration using only pointers instead. Fill in the template below. void count_pos2 (List *p, int *k) { *k = 0; while ( ) { if (p->data > 0) (*k)++; ; 8

3. (2 points) Your function from part 2 still has a bug in that it does not always count the number of positive elements in the list at p and stores it at k. Explain the problem. 4. (5 points) Fix the problem you identified in part 3. Your function should also run faster by reducing memory accesses when compared to the function in part 2. 9

5. Out-of-Order Execution (7 points) 1. (5 points) The inner loop corresponding to our answer to part 4 of the previous problem has the following form:.l48:.l47: movl 4(%eax), %ecx # load 4(%eax.0) --> %ecx.1 testl %ecx, %ecx jle.l47 incl %edx movl (%eax), %eax testl %eax, %eax jne.l48 Annotate each line with the execution unit operations for one iteration, assuming the inner branch is not taken. To get you started, we have filled in the first operation. 2. (2 points) Assuming most numbers in a list are positive and branch predictions are correct, give a plausible lower bound on the CPE for the inner loop based on the execution unit operations. Optimistically assume memory accesses are cache hits. 10

6. Cache Memory (8 points) Assume we have byte-addressable memory with addresses that are 12 bits wide. We have a 2-way set associative cache with with 4 byte block size and 4 sets. 1. (3 points) On the template below, show the portions of an address that make up the tag, the set index, and the block offset. 11 10 9 8 7 6 5 4 3 2 1 0 2. (5 points) Consider the following cache state, where all addresses, tags, and values are given in hexadecimal format. Set Index Tag Valid Byte 0 Byte 1 Byte 2 Byte 3 0 00 1 40 41 42 43 83 1 FE 97 CC D0 1 00 1 44 45 46 47 83 0 2 00 1 48 49 4A 4B 40 0 3 FF 1 9A C0 03 FF 00 0 For each of following memory accesses indicate if it will be a cache hit or miss, when they are carried out in sequence as listed. Also give the value of a read if it can be infered from the information in the cache. Operation Address Hit? Read Value (or Unknown) Read 0x834 Write 0x836 (not applicable) Read 0xFFD 11