CSE 351 Midterm - Winter 2017

Similar documents
CSE 351 Midterm - Winter 2015

CSE 351 Midterm - Winter 2015 Solutions

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

1 Number Representation(10 points)

CSE351 Spring 2018, Midterm Exam April 27, 2018

Do not turn the page until 5:10.

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

CSE 351 Midterm Exam

CSE 351 Spring 2017 Midterm Exam (8 May 2017)

Do not turn the page until 5:10.

Question Points Score Total: 100

UW CSE 351, Winter 2013 Midterm Exam

CSE 351 Final Exam - Winter 2017

Do not turn the page until 5:10.

Do not turn the page until 5:10.

CSE 351 Midterm Exam Spring 2016 May 2, 2015

CS429: Computer Organization and Architecture

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

x86-64 Programming II

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 11:30.

CS367 Test 1 Review Guide

Machine-level Programs Procedure

x86 Programming II CSE 351 Winter

CS , Fall 2007 Exam 1

The Stack & Procedures

CSE351 Autumn 2013 Final Exam (11 Dec 2013)

Assembly Programming III

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

Machine-Level Programming III: Procedures

Machine Program: Procedure. Zhaoguo Wang

CS 3330 Exam 1 Fall 2017 Computing ID:

Review addressing modes

x86 64 Programming II

How Software Executes

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

Assembly Programming IV

15-213, Fall 2007 Midterm Exam

Intel x86-64 and Y86-64 Instruction Set Architecture

x86-64 Programming III & The Stack

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

x86-64 Programming III

Princeton University Computer Science 217: Introduction to Programming Systems. Assembly Language: Function Calls

Areas for growth: I love feedback

Computer Architecture and System Programming Laboratory. TA Session 3

Machine-Level Programming (2)

Lecture 3 CIS 341: COMPILERS

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

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

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

Instructions and Instruction Set Architecture

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

18-600: Recitation #4 Exploits (Attack Lab)

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

The Stack & Procedures

Buffer Overflow Attack (AskCypert CLaaS)

Machine Programming 3: Procedures

Question Points Score Total: 100

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 12

Procedures and the Call Stack

Machine- Level Representa2on: Procedure

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

Computer Systems C S Cynthia Lee

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

CS , Spring 2004 Exam 1

CSE351 A, Grossman, Midterm Exam

Computer Organization: A Programmer's Perspective

18-600: Recitation #3

231 Spring Final Exam Name:

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

Assembly Programming IV

18-600: Recitation #4 Exploits

CSCI 2021: x86-64 Control Flow

CS , Fall 2001 Exam 1

Do not turn the page until 12:30.

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

Question 1: Number Representation

last time Assembly part 2 / C part 1 condition codes reminder: quiz

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

Assembly Language: Function Calls

Assembly Language II: Addressing Modes & Control Flow

CS , Fall 2002 Exam 1

CS429: Computer Organization and Architecture

Representing and Manipulating Integers. Jo, Heeseung

Machine Language CS 3330 Samira Khan

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

CS 261 Fall Machine and Assembly Code. Data Movement and Arithmetic. Mike Lam, Professor

Machine/Assembler Language Putting It All Together

Building an Executable

Recitation: Bomb Lab. September 17 th 2018

Do not turn the page until 12:30.

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

CS 2150 Exam 2, Spring 2018 Page 1 of 6 UVa userid:

3. Address Translation (25 pts)

CSC 252: Computer Organization Spring 2018: Lecture 6

cmovxx ra, rb 2 fn ra rb irmovq V, rb 3 0 F rb V rmmovq ra, D(rB) 4 0 ra rb mrmovq D(rB), ra 5 0 ra rb OPq ra, rb 6 fn ra rb jxx Dest 7 fn Dest

CS527 Software Security

+ Machine Level Programming: x86-64 History

CSCI 2121 Computer Organization and Assembly Language PRACTICE QUESTION BANK

Transcription:

CSE 351 Midterm - Winter 2017 February 08, 2017 Please read through the entire examination first, and make sure you write your name and NetID on all pages! We designed this exam so that it can be completed in 50 minutes. There are 5 problems for a total of 100 points. There is one extra credit problem worth 10 extra points if you have time and feel adventurous :). 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. Number Representation 20 2. Addresses 10 3. Assembly and C 30 4. Pointers and Values 20 5. Procedures 20 TOTAL 100 Extra Credit 10 1

1. Number Representation (20 points) Integers (a) Assuming unsigned integers, what is the result when you compute UMAX+1? UMIN (b) Assuming two s complement signed representation, what is the result when you compute TMAX+1? TMIN (or (-TMAX - 1)) (c) How would you encode a date with the format <day=dd> <month=mm> <year=yyyy> in a 32 bit word in a way that is easy to extract the day, month and year with masks? Write a C expression that extracts the day only. (multiple answers accepted) MSB LSB DD MM YYYY 5bit 4bit 23bit uint32 date = /* a date in your format */; uint32 day = (date >> 27) & 0b11111 ; Floating Point (d) Floating point is an approximation of real numbers. What are the components of a floating point number? And what do you get when you add a very large floating point number with a very small floating point number? Why? Please be concise :) Floating point numbers have sign, mantissa, and exponent components. Ans: When you add a very large floating-point number with a very small one, the resulting answer will be the same as the very large number. This is because of the limited number of mantissa bits after normalization the bits representing the very small number will be truncated away. 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 concisely. Ans: i==j will return false. i holds the estimate of 5.0 as an integer, whereas j holds the bit-pattern representation of 5.0 in floating-point, which is not the 2 of 9

2. Addresses (10 points) The table below represents a chunk of memory on a little-endian machine with 64-bit words. For example, address 0x27 contains byte 0xAB. Word Address +0 +1 +2 +3 +4 +5 +6 +7 0x0000000000000000 77 66 55 44 33 22 11 00 0x0000000000000008 0x0000000000000010 0x0000000000000018 03 00 00 00 00 00 00 00 0x0000000000000020 0xAB (a) Write word 0x0011223344556677 at address 0x00. (b) In location 0x18, write a pointer that points to a location that stores value 0x44. 3 of 9

3. Assembly and C (30 points) Consider the following x86-64 assembly, (partially blank) C code, and memory listing. Addresses and values are 64-bit. foo: movl $0, %eax L1: testq %rdi, %rdi je L2 movq (%rdi), %rdi addl $1, %eax jmp L1 L2: ret int foo(long *p) { int result = 0; while (p!= NULL) { // cast p, then deref p = *(long**)p; result = result + 1; } return result; } Address 0x1000 0x1008 0x1010 0x1018 0x1020 0x1028 0x1030 0x1038 0x1040 0x1048 Value 0x1030 0x1020 0x1000 0x0000 0x1030 0x1008 0x0000 0x1038 0x1048 0x1040 (a) Given the assembly of foo, fill in the blanks of the C version. (b) Trace the execution of the call to foo((long*)0x1000) in the table to the right. Show which instruction is executed in each step until foo returns. In each space, place the the assembly instruction and the values of the appropriate registers after that instruction executes. You may leave those spots blank when the value does not change. You might not need all steps listed on the table. Instruction %rdi (hex) %eax (decimal) movl 0x1000 0 testq je movq 0x1030 addl 1 jmp testq je movq 0x0 addl 2 jmp testq je ret (c) Briefly describe the value that foo returns and how it is computed. Use only variable names from the C version in your answer. It returns the depth of the pointer chain from p by counting how many times it can be dereferenced before it s NULL. 4 of 9

4. Pointers and Values (20 points) Consider the following variable declarations: 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 = {aa, bb, cc}; Variable aa bb cc w x y z Address 0x000 0x100 0x200 0x300 0x400 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 0x400 N/A int y[0] 0x500 0 int *(y+1) 0x504 1 int *(z[0]+1) 0x604 211 int w[1] 0x308 0x100 int* 5 of 9

5. Procedures (20 points) Below is a simple program that calls a function bigbig with several arguments. A portion of the result of objdump is shown beside it. int main() { return bigbig(1, 2, 3, 4, 5, 6, 7); } main: 100000f20: 100000f25: 100000f2a: 100000f2f:... omitted... 100000f34: 100000f3a: 100000f40: 100000f42: callq 0x100000f00 <bigbig> 100000f47:... omitted... 100000f48: retq Suppose you ran gdb on this program, running the command break bigbig. Draw the state of the stack and registers below at the time of the breakpoint (right before the instruction at 0x100000f00 executes). Assume that, before doing any setup for the call to bigbig, %rsp = 0x1ffefff8 and all other relevant registers are set to 0. If a value on the stack in the given table is still unknown after execution, you may leave that box blank. Stack Address 0x1ffefff8 0x1ffefff0 0x1ffeffe8 0x1ffeffe0 0x1ffeffd8 Value 0x7 0x100000f00 Reg Value Reg Value %rax %r8 5 %rbx %r9 6 %rcx 4 %r10 %rdx 3 %r11 %rsi 2 %r12 %rdi 1 %r13 %rsp 0x1ffeffe8 %r14 %rbp %r15 6 of 9

Extra Credit (10 points) What does the code below compute? int mystery(unsigned x) { x = (x & 0x55555555) + ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF); return x; } It s POPCOUNT, which counts the number of set bits in x. 7 of 9

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/decimal/binary help: Decimal Hexadecimal Binary 0 0 0000 1 1 0001 2 2 0010 3 3 0011 4 4 0100 5 5 0101 6 6 0110 7 7 0111 8 8 1000 9 9 1001 10 A 1010 11 B 1011 12 C 1100 13 D 1101 14 E 1110 15 F 1111 8 of 9

Assembly Code Instructions: push pop call ret mov lea D(base, index, scale), dest 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 (does not load) and place in register dest. (dest = D + (base + (index * scale)) when scale is 1,2,4,8) 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 je/jne js/jns cmp test jump to address conditional jump to address if zero flag is / is not set conditional jump to address if sign flag is / is not set subtract src (1 st operand) from dst (2 nd ) and set flags, discard result bit-wise AND src and dst and set flags, discard result 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 9 of 9