Unformatted text preview:

CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 1 of 10 CMSC 212 FINAL EXAM (Spring 2005) Name _GRADING DIRECTIONS_ Discussion Section Time (circle one): 12:00 1:00 2:00 3:00 Asad Konstantin (1) This exam is closed book, closed notes, and closed neighbor. No calculators are permitted. Violation of any of these rules will be considered academic dishonesty. (2) You have 120 minutes to complete this exam. If you finish early, you may turn in your exam at the front of the room and leave. However if you finish during the last ten minutes of the exam please remain seated until the end of the exam so you don't disturb others. Failure to follow this direction will result in points being deducted from your exam. (3) Write all answers on the exam. If you need additional paper, we will provide it. Make sure your name is on any additional sheets. (4) Partial credit will be given for most questions assuming we can figure out what you were doing. (5) Please write neatly. Print your answers, if that will make your handwriting easier to read. If you write something, and wish to cross it out, simply put an X through it. Please clearly indicate if your answer continues onto another page. 1.) [20 points] a) Explain the purpose of C's preprocessor and give two different preprocessor directives (with explanation of their purpose. Question Possible Score 1 20 2 11 3 15 4 12 5 10 6 12 7 20 Total 100CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 2 of 10 [3 pnts] Makes a pass over the program substituting pre-processor directives with values or filles from other locations. [2 pnts] #include – include a file into the file being compiled [2 pnts] #define – defines a value for a preprocessor macro (a constant or short bit of code). b) What is the purpose of each of these compiler switches? 1. [1 pnts] -o The next switch indicates the output file for the compilation 2. [1 pnts] -O Turns on the optimizer which tries to generate faster code 3. [1 pnts] -c Indicates that the compiler should compile to a .o file, but not invoke a linker to produce an executable file 4. [1 pnts] -g requests the compiler to generate additional output to enable running the debugger on the resulting executable. c) According to the code segment in the first column - write the type of each of the given expressions in the third column. (i.e. Integer, Integer pointer, address of an integer pointer, etc) If you can not tell from the code given, you must write the word "unknown". You do not need to worry about what value (or even if there is space allocated) - just what type it would be. T [1 pnts] Undefined, C is case sensitive and only lowercase t is defined. *(&a) [1 pnts] int &b [1 pnts] Pointer to int or address of an integer q [1 pnts] int int a, b; int* t, q; *t [1 pnts] int d) Given one example of a situation where optimizing wall time (vs. process time) makes more sense and one where optimizing process time (vs. wall time) makes sense. [2 pnts] If your program is I/O bound, you should optimize wall time which is not calculated as process time.CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 3 of 10 [2 pnts] If your program is compute bound, you should optimize for process time so that the impact of other processes running on the system (measured in wall time) will not be a factor.CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 4 of 10 2.) [11 points] Give all of the output of the following code on the lines given (it does compile and run). If you have a situation where you have a pointer into non-allocated space, use ??? to indicate that value. OUTPUT goes on these lines 2 3 2 13 7 7 5 5 ? 1 point for each value up to -2 for extra values or incorrect end of lines etc. #include <stdio.h> #include <malloc.h> int f1(int *x){ *x = 2; x = (int*)calloc(sizeof(int),1); *x = 3; return *x; } int* f2( int x, int **y){ int m= 8; int *t = &m; x += m--; y = &t; printf("%d %d %d\n",x,*t,**y); return t; } int main(void){ int a,b,c; int *p, *q, *r; a = 5; p = &a; b = f1(p); printf("%d %d %d\n",a,b,*p); c = 5; q = &c; r = f2( c,&q); printf("%d %d %d\n",c,*q,*r); return 0; }CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 5 of 10 3.) [15 points] Write the assembly code for the following function (following the stack conventions of the machine): void foo(int x, y) { if (x > 0) { foo(x-1, y); else if (y > 0) { printf(“%d\n”, y); } } foo: Store R14 R15 0 Load R10 R0 #1 Negate R10 Add R15 R10 R15 Move R11 R2 Add R2 R10 R2 Negate R11 Bnn R11 skip1 Branch R14 R0 foo Branch R0 R0 skip2 skip1: Move R12 R3 Negate R12 Bnn R12 skip2 Output R3 skip2: Load R10 R0 #1 Add R15 R10 R15 Load R14 R15 0 Branch R0 R14 0 Grading: 2 points for correctly testing and branching on x > 0 2 points for correctly storing the x and y values 2 points for storing stack pointer 3 points for initiating the recursive call 2 points for restoring stack pointer 2 points for coming out of the recursion 2 points for the output when y > 0CMSC 212 - FINAL EXAM - Spring 2005 - Hollingsworth/Plane - p. 6 of 10 4.) [12 points] Write a makefile which builds the programs with the following dependencies. A solid line indicates a file included by another file and a dash line indicates a file that should be built from one or more files. You must write the makefile in such a way that typing the command make at the command line will create both executable files based on the correct versions of the files in the current directory. all: prog1 prog2 yourStuff.o: yourStuff.c private1.h common.h helpers.o: helpers.c common.h myStuff.o: myStuff.c common.h private2.h prog1: yourStuff.o helpers.o gcc –o prog1 yourStuff.o helpers.o prog2: myStuff.o helpers.o gcc –o prog2 myStuff.o helpers.o GRADING: 12 points total 3 points for both executables being the first directive (type make to compile both) OK if did or didn't use the implied dependencies (not putting x.c in the list) OK if did or didn't use the implied constructions (not putting the cc -c x.c in the list) 4 points for the .o creation directives -1 point for each missing


View Full Document

UMD CMSC 212 - FINAL EXAM

Download FINAL EXAM
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view FINAL EXAM and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view FINAL EXAM 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?