CS 201 Winter 2014 (Karavanic) Final Exam

Similar documents
15-213, Fall 2007 Final Exam

CS , Fall 2001 Exam 1

CS , Fall 2002 Exam 1

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

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

EECS 213 Fall 2007 Midterm Exam

CS , Fall 1998 Final Exam

Datorarkitektur, 2009 Tentamen

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

CS , Spring 2004 Exam 1

CMSC 313 Lecture 12. Project 3 Questions. How C functions pass parameters. UMBC, CMSC313, Richard Chang

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

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

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

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

CMSC 313 Lecture 12 [draft] How C functions pass parameters

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

CS , Fall 2004 Exam 1

THEORY OF COMPILATION

Machine Programming 1: Introduction

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

Assembly I: Basic Operations. Jo, Heeseung

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

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

Machine Programming 3: Procedures

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

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

Machine-level Programming (3)

211: Computer Architecture Summer 2016

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

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

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

Process Layout, Function Calls, and the Heap

Machine-Level Programming II: Control and Arithmetic

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

Instruction Set Architecture

CISC 360 Instruction Set Architecture

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Process Layout and Function Calls

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

An Experience Like No Other. Stack Discipline Aug. 30, 2006

CPEG421/621 Tutorial

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

Instruction Set Architecture

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING PREVIEW SLIDES 16, SPRING 2013

Instruction Set Architecture

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

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

CS213. Machine-Level Programming III: Procedures

CISC 360. Machine-Level Programming I: Introduction Sept. 18, 2008

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

System Programming and Computer Architecture (Fall 2009)

CS , Spring 2002 Exam 2

CPSC W Term 2 Problem Set #3 - Solution

Machine-Level Programming III: Procedures

Sungkyunkwan University

Assembly Language Programming - III

Assembly III: Procedures. Jo, Heeseung

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

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Lab 10: Introduction to x86 Assembly

Machine Programming 4: Structured Data

Assembly Language: Function Calls

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

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

The course that gives CMU its Zip! Machine-Level Programming III: Procedures Sept. 17, 2002

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

CS 3843 Final Exam Fall 2012

Assembly Language: Function Calls" Goals of this Lecture"

CS61 Section Solutions 3

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

Instruction Set Architectures

Self-assessment Exercise

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

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

Stack Discipline Jan. 19, 2018

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

The course that gives CMU its Zip! Machine-Level Programming I: Introduction Sept. 10, 2002

Assembly Language: Function Calls" Goals of this Lecture"

CS241 Computer Organization Spring Addresses & Pointers

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

Computer Systems Organization V Fall 2009

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

Do not turn the page until 5:10.

CPS104 Recitation: Assembly Programming

CSE 351 Spring 2017 Final Exam (7 June 2017)

Chapter 3 Machine-Level Programming II Control Flow

Assignment 11: functions, calling conventions, and the stack

Machine-Level Programming Introduction

Introduction Selected details Live demos. HrwCC. A self-compiling C-compiler. Stefan Huber Christian Rathgeb Stefan Walkner

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

Credits to Randy Bryant & Dave O Hallaron

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

X86 Assembly -Procedure II:1

CS241 Computer Organization Spring Loops & Arrays

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

Full Name: CISC 360, Fall 2008 Example of Exam

Instructor: Alvin R. Lebeck

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

Transcription:

CS 201 Winter 2014 (Karavanic) Final Exam Your Name: (1 point) Instructions: - Be sure to write your name on the first sheet. - All answers, and all work submitted in support of answers, should be written on this exam paper. - You may not use lecture notes, books, or any other written or electronic material for this exam, EXCEPT for one 8.5 x 11 inch sheet of paper full of notes. You may not use a calculator or any other electronic tools. - Do not begin the test until instructed to do so. Stop working on the test when instructed to do so. You will have 2 hours to complete the test. - Work individually. Do not discuss the test with anyone, do not copy answers from other students, and do not allow others to copy your work. - In parts B and C, if you arrive at an incorrect answer, showing your work may result in partial credit. Good luck!

Part A. Multiple Choice (3 points each; 30 points total) Circle the one best choice for each of these 10 questions. 1. How does x86 assembly store the return value when a function is finished? (a) The ret instruction stores it in a special retval register. (b) By convention, it is always in %eax. (c) It is stored on the stack just above the (%ebp) of the callee. (d) It is stored on the stack just above all the arguments to the function. 2. In IEEE floating point, what would be an effect of allocating more bits to the exponent part by taking them from the fraction part? (a) You could represent fewer numbers, but they could be much larger. (b) You could represent the same numbers, but with more decimal places. (c) You could represent both larger and smaller numbers, but with less precision. (d) Some previously representable numbers would now round to infinity 3. Consider the following two blocks of code, found in separate files: /* main.c */ int i=0; int main() { foo(); exit(0); /* foo.c */ int i = 1; void foo() { printf( %d, i); What will happen when you attempt to compile, link, and run this code? (a) It will fail to compile. (b) It will fail to link. (c) It will raise a segmentation fault. (d) It will print 0. (e) It will print 1. (f) It will sometimes print 0 and sometimes print 1.

4. Consider the following C functions and assembly code: int fun7(int a) { return a * 30; int fun8(int a) { return a * 34; int fun9(int a) { return a * 18; pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax sall $4,%eax addl 8(%ebp),%eax addl %eax,%eax movl %ebp,%esp popl %ebp ret Which of the functions compiled into the assembly code shown? (a) fun7 (b) fun8 (c) fun9 (d) None 5. To delete symbol table information from an object file I should: (a) compile with the - g option (b) use GPROF (c) use STRIP (d) use LDD 6. Which of these uses of caching is not crucial to program performance? (a) Caching portions of physical memory (b) Caching virtual address translations (c) Caching virtual addresses (d) Caching virtual memory pages (e) None of the above (that is, they are all crucial)

7. Suppose a local variable int myint is declared in a function named func. Which of the following is considered safe in C? (a) func returns &myint and the caller dereferences the returned pointer. (b) func returns &myint and the caller prints the returned pointer to the screen (c) func sets the value of a global variable to &myint and returns. The global variable is unchanged up to the point another function dereferences the global variable. (d) None of the above 8. I can get a listing of all of the system calls made by a program using: (a) STRACE (b) PS (c) TOP (d) OBJDUMP 9. Within a loop, my code accesses the same loop index variable repeatedly. This is an example of: (a) temporal locality (b) spatial locality (c) recursion (d) onomatopoeia 10. Before executing a function's instructions we need to: (a) add function arguments to the stack (b) create a new stack frame (c) save register values (d) all of the above

Part B. Short answers (5 points each; 25 points total) 1. The smallest, fastest memory at the top of the memory hierarchy is the: 2. A #define in your C program will be handled by the: 3. Suppose you are given the task of improving the performance of a program consisting of 3 parts. Part A requires 20% of the overall run time, part B requires 30%, and part C requires 50%. You determine that for $1000 you could either speed up part B by a factor of 3.0 or part C by a factor of 1.5. Which choice would maximize performance? Circle one: B C 4. What call is used by a debugger to halt a running program and change some of its current variable values?

5. Consider the C program below. (For space reasons, we are not checking error return codes, so assume that all functions return normally.) main() { if (fork() == 0) { if (fork() == 0) { printf("3"); else { pid_t pid; int status; if ((pid = wait(&status)) > 0) { printf("4"); else { if (fork() == 0) { printf("1"); exit(0); printf("2"); printf("0"); return 0; Out of the 5 outputs listed below, circle only the valid outputs of this program. Assume that all processes run to normal completion. A. 2030401 B. 1234000 C. 2300140 D. 2034012 E. 3200410

Part C. Longer Answers C.1. (2 pts each; 12 points total) The following table gives the parameters for a number of different caches, where is the number of physical address bits, is the cache size (number of data bytes), is the block size in bytes, and is the number of lines per set. For each cache, determine the number of cache sets (S), tag bits (t), set index bits (s), and block offset bits (b). Cache m C B E S t s b 1. 32 1024 4 4 2. 32 1024 4 256 3. 32 1024 8 1 4. 32 1024 8 128 5. 32 1024 32 1 6. 32 1024 32 4

C.2. (8 points): Consider the source code below, where M and N are constants declared with #define. int array1[m][n]; int array2[n][m]; int copy(int i, int j) { array1[i][j] = array2[j][i]; Suppose the above code generates the following assembly code: copy: pushl %ebp movl %esp,%ebp pushl %ebx movl 8(%ebp),%ecx movl 12(%ebp),%ebx leal (%ecx,%ecx,8),%edx sall $2,%edx movl %ebx,%eax sall $4,%eax subl %ebx,%eax sall $2,%eax movl array2(%eax,%ecx,4),%eax movl %eax,array1(%edx,%ebx,4) popl %ebx movl %ebp,%esp popl %ebp ret What are the values of M and N? M= N=

C.3. (2 points each; 8 points) The heart of the game SimAquarium is a tight loop that calculates the average position of 256 algae. You are evaluating its cache performance on a machine with a 1024-byte direct-mapped data cache with 16-byte blocks (B = 16). You are given the following definitions: struct algae-position { int x; int y; ; struct algae_position grid[16][16]; int total_x = 0, total_y = 0; int i, j; Assume the following: sizeof(int) == 4. grid begins at memory address 0 The cache is initially empty The only memory accesses are to the entries of the array grid. Variables i, j, total_x and total_y are stored in registers. Your job is to determine the cache performance for the following code: for (i = 0; i < 16; i++ ) { for (j = 0; j < 16; j++) { total_x += grid[j][i].x; total_y += grid[j][i].y; A. What is the total number of reads? B. What is the total number of reads that miss in the cache? C. What is the miss rate? D. What would the miss rate be if the cache were twice as big?

C.4. (2 points each; 16 points total): Dr. Evil has returned! He has placed a binary bomb in this exam! Once again, Dr. Evil has made the disastrous mistake of leaving behind some of his source code. Can you save all of mankind (or at least your grade on this question), and tell us what this bomb does? The C source code Dr. Evil forgot to erase: /* bomb.c: Use new computer technology to blow up exams! -- Dr. Evil */ #include <stdio.h> #include <stdlib.h> extern long secret_unsolvable_puzzle_fn(long input); void explode_bomb() { printf("you fail! Mwhahahahaha!!!\n"); exit(8); int main(int argc,char *argv[]) { if(argc!= 2) { printf("usage: %s <magic password>\n", argv[0]); explode_bomb(); if(secret_unsolvable_puzzle_fn(atol(argv[1])) == 0) explode_bomb(); printf("curses, foiled again! You get paid one MEEELLION DOLLARS!\n"); return 0; The IA32 disassembly for the stuff Dr. Evil did erase: secret_unsolvable_puzzle_fn: 80485c0: 55 pushl %ebp 80485c1: 89 e5 movl %esp,%ebp 80485c3: 8b 45 08 movl 0x8(%ebp),%eax 80485c6: 85 c0 testl %eax,%eax 80485c8: 74 1d je 80485e7 80485ca: 8d 14 00 leal (%eax,%eax,1),%edx 80485cd: 81 fa 42 53 00 cmpl $21314,%edx 80485d2: 00 80485d3: 77 0a ja 80485df 80485d5: 01 c2 addl %eax,%edx 80485d7: 81 fa 42 53 00 cmpl $21314,%edx 80485dc: 00 80485dd: 76 f6 jbe 80485d5 80485df: 81 fa 43 53 00 cmpl $21315,%edx 80485e4: 00 80485e5: 74 02 je 80485e9 80485e7: 31 c0 xorl %eax,%eax 80485e9: 89 ec movl %ebp,%esp 80485eb: 5d popl %ebp 80485ec: c3 ret

A. Does the function secret_unsolvable_puzzle_fn() contain any of the following (circle either yes or no): loops: yes no if statements: yes no function calls: yes no recursion: yes no B. For each of the following input values, circle whether it defuses or explodes the bomb: input = 0: defuses explodes input = 1: defuses explodes input = 7105: defuses explodes input = 10657: defuses explodes