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

Similar documents
CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm Solutions

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

CIS 2107 Computer Systems and Low-Level Programming Fall 2010 Midterm

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

Process Layout and Function Calls

Process Layout, Function Calls, and the Heap

CS 3843 Final Exam Fall 2012

CS , Fall 2001 Exam 1

CIT Week13 Lecture

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

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

CS , Fall 2004 Exam 1

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

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

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

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

CS , Fall 2002 Exam 1

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

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

Section 4: Threads and Context Switching

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

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

CSE2421 FINAL EXAM SPRING Name KEY. Instructions: Signature

Assembly I: Basic Operations. Jo, Heeseung

CPEG421/621 Tutorial

ASSEMBLY I: BASIC OPERATIONS. Jo, Heeseung

Assembly Language: Function Calls

Datorarkitektur, 2009 Tentamen

Instruction Set Architecture

Instruction Set Architecture

Assembly Language: Function Calls" Goals of this Lecture"

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

Assembly Language: Function Calls" Goals of this Lecture"

CPS104 Recitation: Assembly Programming

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

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

Assembly I: Basic Operations. Computer Systems Laboratory Sungkyunkwan University

CS241 Computer Organization Spring 2015 IA

Midterm Exam CSC February 2009

CS 201 Winter 2014 (Karavanic) Final Exam

CS61, Fall 2012 Midterm Review Section

EECS 213 Fall 2007 Midterm Exam

Implementing Threads. Operating Systems In Depth II 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

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

Second Part of the Course

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

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

Instruction Set Architecture

CISC 360 Instruction Set Architecture

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Giving credit where credit is due

Machine Programming 4: Structured Data

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

System Programming and Computer Architecture (Fall 2009)

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

UW CSE 351, Winter 2013 Midterm Exam

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

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

211: Computer Architecture Summer 2016

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

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

CSE351 Spring 2018, Midterm Exam April 27, 2018

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

15-213/18-243, Summer 2011 Exam 1 Tuesday, June 28, 2011

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers. Kevin Webb Swarthmore College March 1, 2016

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

Representation of Information

Instructor: Alvin R. Lebeck

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

Instruction Set Architectures

Instruction Set Architecture

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

Instruction Set Architectures

x86 assembly CS449 Fall 2017

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

CSC 2400: Computing Systems. X86 Assembly: Function Calls

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

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

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

Low-Level Essentials for Understanding Security Problems Aurélien Francillon

ASSEMBLY III: PROCEDURES. Jo, Heeseung

Reverse Engineering II: Basics. Gergely Erdélyi Senior Antivirus Researcher

Assembly III: Procedures. Jo, Heeseung

Machine Language, Assemblers and Linkers"

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

CS241 Computer Organization Spring Loops & Arrays

Machine-Level Programming III: Procedures

231 Spring Final Exam Name:

W4118: PC Hardware and x86. Junfeng Yang

Important From Last Time

CS , Spring 2004 Exam 1

Computer Systems CEN591(502) Fall 2011

Important From Last Time

CS241 Computer Organization Spring Introduction to Assembly

Assembly Language: IA-32 Instructions

x86 architecture et similia

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

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

Transcription:

Spring 2012 Name: Page Points Score 1 14 2 7 3 6 4 5 5 5 6 5 7 10 8 11 9 10 10 9 11 8 12 10 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. Unless you are told otherwise, you may use any functions in the Standard C Library. For each of the questions of this quiz, you can assume the following sizes for C data types: type bytes char 1 short 2 int 4 long 8 float 4 double 8 void* 4 i

1. Please place the letter of the best answer for each in the answer line. A L1 B loader C nanoseconds D cylinder E L2 F data G DRAM H BSS I SRAM J compiler K track L EAX M seconds N instruction pointer or program counter O flash P sector Q heap R magnetic disk S assembler T stack U locality V preprocessor W symbol table X CPU Y EBP Z milliseconds (1 point) (a) Translates a high level language program into assembly language. (a) (1 point) (b) Roughly one million times slower, cheaper, and larger than main memory or cache. (1 point) (c) Malloc and free manage this area of memory. (1 point) (d) Translates assembly language into machine code. (1 point) (e) Segment for area of memory allocated by malloc( ). (1 point) (f) Tendency for programs to access multiple objects in a block. (1 point) (g) Translates assembly language programs into machine language. (1 point) (h) Area of memory used for initialized global variables. (b) (c) (d) (e) (f) (g) (h) (1 point) (i) In a collection of disk platters, a set of tracks equidistant from the center of the platter. (i) (1 point) (j) Processor register that contains the address of the next instruction to be executed. (1 point) (k) Contains the return value of functions which return ints. (1 point) (l) The larger but slower cache. Still much faster than main memory. (1 point) (m) Time it takes to read from disk. (1 point) (n) Time to read from on-cpu cache. (j) (k) (l) (m) (n) 1 of 13 exam continues...

(2 points) 2. What is 111101011010 2 + 1011111011 2 in base 2? 1 1 1 1 0 1 0 1 1 0 1 0 2 + 1 0 1 1 1 1 1 0 1 1 2 (2 points) 3. What is 5696C1B 16 + DA778 16 in base 16? 5 6 9 6 C 1 B 16 + D A 7 7 8 16 4. Some tricky declarations. Write a very brief description in English of what is declared. For example, if the question is int func(int A[]), you d write, func is a function which is passed an array of int and returns an int. (1 point) (a) char (*p)[10]; (1 point) (b) int (*p[ ])( ); (1 point) (c) int (*p( ))[ ]; out of a possible 7 2 of 13 exam continues...

(6 points) 5. Encoding a floating-point number. (a) What is 0.4375 10 in fixed-point binary? (b) What is 199.4375 10 in fixed-point binary? (c) In a 32-bit C float variable, how many bits are used for the sign? (d)... how many for the exponent? (e)... how many for the mantissa? (c) (d) (f) What is the value for bias when exponents are stored using as many bits as you ve put for your answer to part d? (e) (g) How would 199.4375 10 be stored in a C float variable? out of a possible 6 3 of 13 exam continues...

(1 point) (a) x y 6. Some bit operations. If we have char x = 0x5C, y = 0xA9;, what is the result of the following operations? Your answer must be in the form of exactly two hex digits 1. (a) (1 point) (b) x y (b) (1 point) (c) x<<2 (c) (1 point) (d) x (d) (1 point) (e) x&0x0f (e) 1 Ignore the possibility of promotion to 32-bit ints. Behave as though we re living in the land of 8-bit arithmetic. out of a possible 5 4 of 13 question 6 continues...

(1 point) (f) x y (f) (1 point) (g) x&&1 (g) (1 point) (h) x-y (h) (1 point) (i)!!x (i) (1 point) (j) x&y (j)

(5 points) 7. If I have the following: int main(void) { int a=10; int b=20; int *p=&a; int *q=p; char *cp = (char*)q; (*p)--; q--; cp--; and memory is laid out like this: cp 1000 q 1004 p 1008 b 1012 a 1016 what do you see if you print: (a) a (b) &a (c) b (d) p (e) *p (f) &p (g) q (h) *q (i) cp (j) &cp (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) out of a possible 5 6 of 13 exam continues...

(10 points) 8. Use the following code to answer the questions. Data sizes are specified on the cover of the exam. 1 struct Stuff { 2 int x; 3 int *p; 4 int A[10]; 5 }; 6 7 int main(void) 8 { 9 struct Stuff s; 10 int A[10]; 11 int x, y; 12 char str[24]; 13 14 x=10; 15 y=20; 16 A[0]=30; 17 strcpy(str, "almost quitting time"); 18 s.x=40; 19 s.p=&y; 20 s.a[0]=50; 21 22 func01(a); 23 func02(str); 24 func03(str); 25 func04(s); 26 27 return 0; 28 } 29 30 void func01(int arr[]) { 31 arr[0]=3333; 32 } 33 34 void func02(char *s) { 35 strcpy(s, "yeah, summer vacation"); 36 } 37 38 void func03(char *s) { 39 s = malloc(40); 40 strcpy(s, "how many more pages is this thing?"); 41 } 42 43 void func04(struct Stuff s) { 44 s.x=4444; 45 *(s.p)=2222; 46 s.a[0]=5555; 47 s.p=malloc(sizeof(int)); 48 *(s.p)=2020; 49 } (a) How many bytes are passed to the function func01( )? (b) How many bytes are passed to the function func02( )? (c) How many bytes are passed to the function func04( )? What is the value of each of the following after func04( ) has been called? (d) x (e) y (f) A[0] (g) s.x (h) s.a[0] (i) *(s.p) (j) str (What s the string?) (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) out of a possible 10 7 of 13 exam continues...

(4 points) 9. For each of the following, suppose that %eax contains the value x, %ecx contains y. What s stored in %edx after the each operation? expression leal (%eax,%ecx, 4), %edx result leal 0xB(,%eax,8), %edx leal 5(%eax,%eax,8), %edx leal 0xE(%eax), %edx 10. Given the C function: int func(int x, int y) { int t;... } return x+y-t; Immediately before func( ) is called, i.e., immediately before the instruction call func, %ebp contains the value 1000 10 and %esp contains the value 960 10. Before func( ) exits (more precisely, just before the leave and return instuctions are executed), what is: (1 point) (a) stored in %ebp? (1 point) (b) stored in %esp? (1 point) (c) the location of x? (1 point) (d) the location of y? (1 point) (e) the most likely location of t? (1 point) (f) the location of the return value? (1 point) (g) the location of the return address? (a) (b) (c) (d) (e) (f) (g) out of a possible 11 8 of 13 exam continues...

(5 points) 11. Write a function which is passed an unsigned int x, and an int n. The function returns the nth least significant nibble of x. For example, if x is 0x01234567, and n is 2, the function returns 5. (5 points) 12. Write the function called slice(int A[ ], int s, int e) which returns a new array consisting of all of the elements of A[ ] from A[s] to A[e] inclusive. It is up to the caller to free the memory allocated by slice. If e<s, the function returns NULL. out of a possible 10 9 of 13 exam continues...

(9 points) 13. Write a C function equivalent to the following assembly (no credit for an answer containing inline assembly). 1.section.text 2.globl mystery 3.type mystery, @function 4 mystery: 5 pushl %ebp 6 movl %esp, %ebp 7 xorl %eax, %eax 8 xorl %ecx, %ecx 9 movl 8(%ebp), %edx 10 begin: 11 cmpl 12(%ebp), %ecx 12 jge done 13 addl (%edx, %ecx, 4), %eax 14 incl %ecx 15 jmp begin 16 done: 17 movl %ebp, %esp 18 popl %ebp 19 ret out of a possible 9 10 of 13 exam continues...

(8 points) 14. Implement the function void reverse(int A[ ], int len), which reverses the order of A[ ], an array of len items. Do not use the [ ] operator. No credit will be given for solutions which use the [ ] operator, or which declare len or more elements of temporary storage. void reverse(int A[ ], int len) { out of a possible 8 11 of 13 exam continues...

(10 points) 15. A common way of storing a spreadsheet is comma-separated text. For example, the following line in a spreadsheet: apple banana cherry some fruit beginning with d could be stored as apple, banana, cherry, some fruit beginning with d. Write the function char **split(char *s) which is passed s, which is a string of comma-separated values, and returns an array of string containing the values in the line terminated by a NULL pointer. Using our current example, we d return: w[0] w[1] w[2] w[3] w[4] apple banana cherry some fruit beginning with d NULL split( ) should return NULL on failure. Hint: if there are n commas in s, there will be n + 1 words. You may use any function in the Standard C Library. out of a possible 10 12 of 13 question 15 continues...

(extra space) 13 of 13 end of exam