CSE 351 Midterm - Winter 2015

Similar documents
CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2017

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

1 Number Representation(10 points)

Do not turn the page until 5:10.

CSE351 Spring 2018, Midterm Exam April 27, 2018

Do not turn the page until 5:10.

CSE 351 Midterm Exam

CSE 351 Spring 2017 Midterm Exam (8 May 2017)

UW CSE 351, Winter 2013 Midterm Exam

CSE 351 Midterm Exam Spring 2016 May 2, 2015

Do not turn the page until 5:10.

CSE351 Autumn 2013 Final Exam (11 Dec 2013)

Do not turn the page until 11:30.

CS-220 Spring 2018 Test 2 Version Practice Apr. 23, Name:

Question Points Score Total: 100

Processor state. Information about currently executing program. %rax, %rdi, ... %r14 %r15. %rsp. %rip CF ZF SF OF. Temporary data

Midterm 1 topics (in one slide) Bits and bitwise operations. Outline. Unsigned and signed integers. Floating point numbers. Number representation

Do not turn the page until 5:10.

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

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

Computer Systems C S Cynthia Lee

Review addressing modes

15-213, Fall 2007 Midterm Exam

Do not turn the page until 12:30.

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

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

Question 1: Number Representation

x86 Programming II CSE 351 Winter

CS , Spring 2004 Exam 1

Machine Program: Procedure. Zhaoguo Wang

Instructions and Instruction Set Architecture

CS , Fall 2007 Exam 1

x86-64 Programming II

Do not turn the page until 12:30.

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

The Stack & Procedures

CS429: Computer Organization and Architecture

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

Winter 2017 CS107 Midterm #2 Examination (Practice #2) Problem Points Score Grader TOTAL 30

CS-220 Spring 2018 Final Exam Version Practice May 10, Name:

Machine-Level Programming (2)

CSCI 2021: x86-64 Control Flow

CS 3330 Exam 1 Fall 2017 Computing ID:

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

x86 64 Programming II

Machine-level Programs Procedure

Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition. Carnegie Mellon

Assembly Programming III

Machine-Level Programming III: Procedures

Introduction to Intel x86-64 Assembly, Architecture, Applications, & Alliteration. Xeno Kovah

Assembly Language II: Addressing Modes & Control Flow

CSCI 356 Fall 2017 : Practice Exam I DO NOT OPEN EXAM PACKET UNTIL INSTRUCTED TO DO SO YOU MAY FILL IN INFORMATION ON THE FRONT NOW

Areas for growth: I love feedback

Functions. Ray Seyfarth. August 4, Bit Intel Assembly Language c 2011 Ray Seyfarth

CS 107. Lecture 13: Assembly Part III. Friday, November 10, Stack "bottom".. Earlier Frames. Frame for calling function P. Increasing address

Buffer Overflow Attack (AskCypert CLaaS)

Question Points Score Total: 100

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12

CS367 Test 1 Review Guide

Intel x86-64 and Y86-64 Instruction Set Architecture

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

CSE 351 Final Exam - Winter 2017

Computer Organization: A Programmer's Perspective

Assembly Programming IV

Winter 2017 March 2, 2017 CS107 2 nd Midterm Examination

231 Spring Final Exam Name:

Machine- Level Representa2on: Procedure

L08: Assembly Programming II. Assembly Programming II. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

x86-64 Programming III & The Stack

CS , Fall 2002 Exam 1

Question F5: Caching [10 pts]

L09: Assembly Programming III. Assembly Programming III. CSE 351 Spring Guest Lecturer: Justin Hsia. Instructor: Ruth Anderson

CS / ECE , Spring 2010 Exam 1

CS356: Discussion #8 Buffer-Overflow Attacks. Marco Paolieri

x86-64 Programming III

CSE 351 Section 4 GDB and x86-64 Assembly Hi there! Welcome back to section, we re happy that you re here

Do not turn the page until 12:30.

It is possible to define a number using a character or multiple numbers (see instruction DB) by using a string.

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

Machine Language CS 3330 Samira Khan

CS356: Discussion #15 Review for Final Exam. Marco Paolieri Illustrations from CS:APP3e textbook

Computer Architecture and System Programming Laboratory. TA Session 3

CS , Fall 2001 Exam 1

CSE351 A, Grossman, Midterm Exam

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 5

Assembly Language: Function Calls

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Computer Architecture I: Outline and Instruction Set Architecture. CENG331 - Computer Organization. Murat Manguoglu

Machine/Assembler Language Putting It All Together

Midterm Exam, Fall 2015 Date: October 29th, 2015

18-600: Recitation #3

Lecture 3 CIS 341: COMPILERS

Structs & Alignment. CSE 351 Autumn Instructor: Justin Hsia

CS , Fall 2004 Exam 1

Assembly Programming IV

Do not turn the page until 12:30.

6.035 Project 3: Unoptimized Code Generation. Jason Ansel MIT - CSAIL

Transcription:

CSE 351 Midterm - Winter 2015 February 09, 2015 Please read through the entire examination first! We designed this exam so that it can be completed in 50 minutes and, hopefully, this estimate will prove to be reasonable. There are 4 problems for a total of 100 points. The point value of each problem is indicated in the table below. Write your answer neatly in the spaces provided. If you need more space, you can write on the back of the sheet where the question is posed, but please make sure that you indicate clearly the problem to which the comments apply. If you have difficulty with part of a problem, move on to the next one. They are independent of each other. The exam is CLOSED book and CLOSED notes (no summary sheets, no calculators, no mobile phones, no laptops). Please do not ask or provide anything to anyone else in the class during the exam. Make sure to ask clarification questions early so that both you and the others may benefit as much as possible from the answers. Good Luck! Name: Student ID: Section: Problem Max Score Score 1 20 2 20 3 25 4 35 EC 15 TOTAL 100 1

1. Number Representation (20 points) Integers (a) Assuming unsigned integers, what is the result when you compute UMAX+1? (b) Assuming two s complement signed representation, what is the result when you compute TMAX+1? Floating Point (c) Give M and E in the floating point representation of 3.75. Express each in both decimal and binary. (Remember, E is the actual value of the exponent, not the encoding with bias) E M Binary Decimal (d) Is the == operator a good test of equality for floating point values? Why or why not? Casting and Pointers (e) Given the following code: float f = 5.0; int i = (int) f; int j = *((int *)&f); Does i==j return true or false? Explain. 2 of 8

2. Assembly and C (20 points) Consider the following x86-64 assembly and C code: <do_something>: cmp $0x0,%rsi <end> xor %rax,%rax sub $0x1,%rsi <loop>: lea (%rdi,%rsi, ),%rdx add (%rdx),%ax sub $0x1,%rsi jns <loop> <end>: retq short do_something(short* a, int len) { short result = 0; for (int i = ; i >= 0 ; ) { ; } return result; } (a) Both code segments are implementations of the unknown function do something. Fill in the missing blanks in both versions. (Hint: %rax and %rdi are used for result and a respectively. %rsi is used for both len and i) (b) Briefly describe the value that do something returns and how it is computed. Use only variable names from the C version in your answer. 3 of 8

3. Pointers and Values (25 points) Consider the following variable declarations assuming x86-64 architecture: int x; int y[11] = {0,1,2,3,4,5,6,7,8,9,10}; int z[][5] = {{210, 211, 212, 213, 214}, {310, 311, 312, 313,314}}; int aa[3] = {410, 411, 412}; int bb[3] = {510, 511, 512}; int cc[3] = {610, 611, 612}; int *w[3] = {aa, bb, cc}; Array aa bb cc w y z Address of First Element 0x000 0x100 0x200 0x300 0x500 0x600 (a) Fill in the table below with the address, value, and type of the given C expressions. Answer N/A if it is not possible to determine the address or value of the expression. The first row has been filled in for you. C Expression Address Value Type (int/int*/int**) x 0x400 N/A int *&x y *y y[0] *(y+1) &(y[10]) z[0]+1 *(z[0]+1) z[0][6] w[1] w[2][0] 4 of 8

4. Recursion (35 points) The fictional Fibonatri sequence is defined recursively for n=0,1,... by the following C code: int fibonatri(int n) { if (n == 0) { return 0; } else if (n == 1) { return 1; } else if (n == 2) { return 2; } else { return fibonatri(n-3) - fibonatri(n-2) + fibonatri(n-1); } } Here is a disassembly of fibonatri(): 000000000040057b <fibonatri>: 40057b: 53 push %rbx 40057c: 48 83 ec 10 sub $0x10,%rsp 400580: 89 7c 24 0c mov %edi,0xc(%rsp) 400584: 83 7c 24 0c 00 cmpl $0x0,0xc(%rsp) 400589: 75 07 jne 400592 <fibonatri+0x17> 40058b: b8 00 00 00 00 mov $0x0,%eax 400590: eb 4c jmp 4005de <fibonatri+0x63> 400592: 83 7c 24 0c 01 cmpl $0x1,0xc(%rsp) 400597: 75 07 jne 4005a0 <fibonatri+0x25> 400599: b8 01 00 00 00 mov $0x1,%eax 40059e: eb 3e jmp 4005de <fibonatri+0x63> 4005a0: 83 7c 24 0c 02 cmpl $0x2,0xc(%rsp) 4005a5: 75 07 jne 4005ae <fibonatri+0x33> 4005a7: b8 02 00 00 00 mov $0x2,%eax 4005ac: eb 30 jmp 4005de <fibonatri+0x63> 4005ae:???????? 4005b2: 83 e8 03 sub $0x3,%eax 4005b5: 89 c7 mov %eax,%edi 4005b7: e8 bf ff ff ff callq 40057b <fibonatri> 4005bc: 89 c3 mov %eax,%ebx 4005be: 8b 44 24 0c mov 0xc(%rsp),%eax 4005c2: 83 e8 02 sub $0x2,%eax 4005c5: 89 c7 mov %eax,%edi 4005c7:???????? 4005cc: 29 c3 sub %eax,%ebx 4005ce: 8b 44 24 0c mov 0xc(%rsp),%eax 4005d2:???????? 4005d5: 89 c7 mov %eax,%edi 4005d7: e8 9f ff ff ff callq 40057b <fibonatri> 4005dc:???????? 4005de: 48 83 c4 10 add $0x10,%rsp 4005e2: 5b pop %rbx 4005e3: c3 retq 5 of 8

(a) Fill in the four blanks in the disassembly. You should be able to gather hints from the surrounding code. (b) What register is used to pass the single argument to fibonatri()? (c) Why is the register %rbx pushed onto the stack at the beginning of the function? (d) Why are iterative solutions generally preferred over recursive solutions from a memory usage perspective? How much of the stack is used during each iteration of fibonatri()? (e) What pattern do numbers in the Fibonatri sequence follow? Extra Credit (15 points) Write a non-recursive function in C with the same output as fibonatri() using only a switch statement (Hint: use the modulus % operator) 6 of 8

References Powers of 2: 2 0 = 1 2 1 = 2 2 1 = 0.5 2 2 = 4 2 2 = 0.25 2 3 = 8 2 3 = 0.125 2 4 = 16 2 4 = 0.0625 2 5 = 32 2 5 = 0.03125 2 6 = 64 2 6 = 0.015625 2 7 = 128 2 7 = 0.0078125 2 8 = 256 2 8 = 0.00390625 2 9 = 512 2 9 = 0.001953125 2 10 = 1024 2 10 = 0.0009765625 Hex help: 0x00 = 0 0x0A = 10 0x0F = 15 0x20 = 32 0x28 = 40 0x2A = 42 0x2F = 47 Assembly Code Instructions: push pop call ret mov lea push a value onto the stack and decrement the stack pointer pop a value from the stack and increment the stack pointer jump to a procedure after first pushing a return address onto the stack pop return address from stack and jump there move a value between registers and memory compute effective address and store in a register add add src (1 st operand) to dst (2 nd ) with result stored in dst (2 nd ) sub subtract src (1 st operand) from dst (2 nd ) with result stored in dst (2 nd ) and bit-wise AND of src and dst with result stored in dst or bit-wise OR of src and dst with result stored in dst sar shift data in the dst to the right (arithmetic shift) by the number of bits specified in 1 st operand jmp jne jns cmp test jump to address conditional jump to address if zero flag is not set conditional jump to address if sign flag is not set subtract src (1 st operand) from dst (2 nd ) and set flags bit-wise AND src and dst and set flags 7 of 8

Register map for x86-64: Note: all registers are caller-saved except those explicitly marked as callee-saved, namely, rbx, rbp, r12, r13, r14, and r15. rsp is a special register. %rax Return Value %r8 Argument #5 %rbx Callee Saved %r9 Argument #6 %rcx Argument #4 %r10 Caller Saved %rdx Argument #3 %r11 Caller Saved %rsi Argument #2 %r12 Callee Saved %rdi Argument #1 %r13 Callee Saved %rsp Stack Pointer %r14 Callee Saved %rbp Callee Saved %r15 Callee Saved 8 of 8