Midterm CSE 131 Winter 2013

Similar documents
Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2012

Midterm CSE 131 Winter 2015

Midterm CSE 131 Fall 2014

Final CSE 131 Fall 2014

Final CSE 131 Fall 2015

Final CSE 131 Winter 2012

Final CSE 131 Winter 2010

CSE 30 Fall 2013 Final Exam

CSE 30 Winter 2014 Final Exam

CSE 30 Fall 2012 Final Exam

Midterm CSE 131B Spring 2005

CSE 30 Winter 2009 Final Exam

Final CSE 131B Spring 2004

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2007 Final Exam

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations

CSE 30 Spring 2006 Final Exam

Do not start the test until instructed to do so!

Chapter 2 Bits, Data Types, and Operations

Final CSE 131B Spring 2005

CSE 30 Fall 2006 Final Exam

Data Representation and Binary Arithmetic. Lecture 2

Do not start the test until instructed to do so!

Chapter 2 Bits, Data Types, and Operations

CS 159 Credit Exam. What advice do you have for students who have previously programmed in another language like JAVA or C++?

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Chapter 8. Characters and Strings

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Chapter 2 Bits, Data Types, and Operations

Do not start the test until instructed to do so!

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Fundamentals of Programming (C)

JAVA OPERATORS GENERAL

ASSIGNMENT 5 TIPS AND TRICKS

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Oberon Data Types. Matteo Corti. December 5, 2001

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Final Exam Practice Questions

Number Representations

Chapter 3. Information Representation

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Midterm CSE 131B Spring 2006

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

The Binary Number System

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Fundamentals of Programming

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Under the Hood: Data Representation. Computer Science 104 Lecture 2

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

Lecture (09) x86 programming 8

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Number Systems Base r

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

CMPSC 311- Introduction to Systems Programming Module: Strings

6.096 Introduction to C++ January (IAP) 2009

Operators & Expressions

Simple Data Types in C. Alan L. Cox

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CSE 5A Final Fall 2006

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Chapter 2 Number System

Prof. Navrati Saxena TA: Rochak Sachan

Problem Max. Points Act. Points Grader

Appendix A Developing a C Program on the UNIX system

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

The following are the data types used in the C programming language:

User s Manual. Xi3000 Scanner. Table of Contents

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

Variables and data types

Fundamental Data Types

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

Final CSE 131B Winter 2003

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Question Points Score Total: 100

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case

2D BARCODE SCANNER CA-SC-20200B

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

3. Provide the routing table of host H located in LAN E, assuming that the host s network interface is called i1. ARes/ComNet

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Transcription:

Login Name Signature _ Name Student ID Midterm CSE 131 Winter 2013 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (21 points) (21 points) (21 points) (23 points) (18 points) (24 points) Subtotal (128 points = 100%) Page 7 (9 points = 7%) Extra Credit Total This exam is to be taken by yourself with closed books, closed notes, no electronic devices. You are allowed one side of an 8.5"x11" sheet of paper handwritten by you. 0

1. Given the following CUP grammar snippet (assuming all other Lexing and terminals are correct): Expr ::= Des AssignOp : System.out.println("A"); :} Expr : System.out.println("B"); :} Des : System.out.println("C"); :} ; Des ::= T_PLUSPLUS : System.out.println("D"); :} Des : System.out.println("E"); :} T_STAR : System.out.println("F"); :} Des : System.out.println("G"); :} T_AMPERSAND : System.out.println("H"); :} Des : System.out.println("I"); :} Des2 : System.out.println("J"); :} ; Des2 ::= Des2 : System.out.println("K"); :} T_PLUSPLUS : System.out.println("L"); :} Des3 : System.out.println("M"); :} ; Des3 ::= T_ID : System.out.println("N"); :} ; AssignOp ::= T_ASSIGN : System.out.println("O"); :} ; What is the output when parsing the follow expression (you should have 18 lines/numbers in your output): *x = ++*y++ Output In the above grammar, what is the associativity of the operators in the third production rule (the Des2 ::= rule)? Which operator in which production has higher precedence in the above grammar: the T_PLUSPLUS in Des production or the T_PLUSPLUS in Des2 production? Is this the pre-increment or the post-increment operator? _ 1

2. Assume the following Reduced-C definitions are correct: structdef RECA int * ptr; structdef RECB RECA * ptr; RECB * ptr; a) What type is (*(*ptr).ptr).ptr? b) What type is ptr->ptr? c) What type is *(ptr->ptr->ptr)? d) What type is *(ptr->ptr)? From our Reduced-C spec this quarter, name a construct which uses structural equivalence _ strict name equivalence _ loose name equivalence _ Given the C array declaration C int a[2][4]; Mark with an A all the memory location(s) where we would find the array element a: a[1][2] low memory high memory Each box represents a byte in memory. Now mark with an B all the memory location(s) where we would find the array element a[0][3] Using the Right-Left rule, write the definition of a variable named CSE that is a pointer to an array of 8 elements where each element is a pointer to a function that takes a pointer to a float and returns a pointer to a double. 2

3. Given the following Reduced-C definitions: function : float & foo1( float & a ) return a; } function : float & foo2( float a ) return a; } function : float foo3( float & a ) return a; } function : float foo4( float a ) return a; } float x; /* global variables */ int y; For each of the following statements, indicate the type of error (if any) that should be reported according to the Project I spec for this quarter. Use the letters associated with the available errors in the box below. x = foo1( 4.2 ); x = foo2( y ); y = foo3( x ); x = foo4( foo4( x ) ); x = foo1( x + y ); x = foo2( &x ); x = foo3( y ); foo4( x ) = foo1( x ); foo1( x ) = (int) foo4( x ); y = (int)foo3( (float)y ); *(int *)&foo2( 42 ) = y; x = foo4( x + y ); &foo2( x ) = (float *)&y; A) No Error B) Argument passed to reference param is not a modifiable L-val C) Argument not assignable to value param D) Argument not equivalent to reference param E) Left-hand operand is not assignable (not a modifiable L-val) F) Right-hand-side type not assignable to left-hand-side type The following RC input program contains *FOUR* erroneous statements per Project I. Indicate which lines are erroneous, and what the error would be from the list of available error messages we provided below. 00: int a = 0123; 01: boolean b = true && false; 02: const int c = 0X420; 03: const float d = c ^ c; 04: float * e = nullptr; 05: function : float & foo() 06: return e[-9000]; 07: auto f = &(++a); 08: return a; 09: a = sizeof(e[c]); 10: return *&foo(); 11: return *e; 12: int[3] g = 0,1,2,3 13: } List of types of errors: A: A syntax error that will not be tested (WNBT) B: Incompatible type to binary operator C: Incompatible type to unary operator D: Left-hand operand is not assignable (not a modifiable L-value) E: Value not assignable to variable's type F: Type of return expression not assignment compatible with function's return type G: Type of return expression not equivalent to the function's return type H: Return expression is not a modifiable L-value I: Initialization value of constant not known at compile-time J: Initialization value not assignable to constant/variable K: Index expression value in array declaration must be > 0 L: Index value is outside legal range M: Invalid operand to sizeof. Not a type or not addressable N: Non-addressable argument to address-of operator O: Number of initializer expressions exceeds the array size P: Array initialization expression is not a constant expression Error #1: Line # Error #2: Line # Error #3: Line # Error #4: Line # Error Type Error Type Error Type Error Type 3

4. Identify whether each of the following will cause an underlying bit pattern change. int a = 5; float b = -4.20; int * ptr1; float * ptr2; void foo( float x, float & y ) /* */ } 1) Yes Underlying bit pattern change 2) No No underlying bit pattern change a = (int) b; foo( a, b ); b = a; a = * (int *) & b; ptr1 = (int *) & b; ptr2 = (float *) ptr1; According to this quarter's Reduced-C grammar, what two Reduced-C constructs must be uppercase symbols? Modifiable L-vals, Non-Modifiable L-vals, R-vals Using the Reduced-C Spec (which closely follows the real C language standard), given the definitions below, indicate whether each expression evaluates to either a A) Non-Modifiable L-val B) Modifiable L-val C) R-val function : int * foo1() /* Function body not important. */ } function : int & foo2() /* Function body not important. */ } float[9] f; float x; const float c = 5.5; float *p = &x; x = c p (int *)&x &x c foo2() f &*p ++x *(f+2) foo1() ++foo2() Consider the following struct definitions in Reduced-C (similar to C/C++). Specify the size of each struct on a typical ILP-32 compiler mode RISC architecture (like ieng9) or 0 if it is an illegal definition. structdef FOO2 FOO2 * a; float b; function : void bar( FOO2 &x) int[10] y; } int[2] c; int d; structdef FOO3 int * a; float b; function : void bar() int x = *this.d; } FOO3 * c; int * d; structdef FOO1 int a; float b; function : void bar() FOO1 *x; } int c; int[4] d; Size Size Size 4

5. Show the memory layout of the following C struct definition taking into consideration the SPARC data type memory alignment restrictions discussed in class. Fill bytes in memory with the appropriate struct member/field name. For example, if member/field name p takes 4 bytes, you will have 4 p's in the appropriate memory locations. If the member/field is an array, use the name followed by the index number. For example, some number of p[0]s, p[1]s, p[2]s, etc. If the member/field is a struct, use the member name followed by its member names (e.g. p.a, p.b). Place an X in any bytes of padding. Structs and unions are padded so the total size is evenly divisible by the strictest alignment requirement of its members. struct foo short a; double b; char c; struct fubar float d; int e; char f[5]; struct foo g; short h; struct fubar fubaz; low memory fubaz: high memory What is the sizeof( struct fubar )? _ What is the offsetof( struct fubar, g.b )? _ What is the alignment restriction for struct foo? _ What is the alignment restriction for struct fubar? _ If struct fubar had been defined as union fubar instead, what would be the sizeof(union fubar)? _ What is the resulting type of the following expression? * (char *) & ( ( (struct foo *) & fubaz ) -> b ) Write the equivalent expression that directly accesses this value/memory location without all the fancy casting and & operators. fubaz. 5

6. Fill in the names of the 5 main areas of the C Runtime Environment as laid out by most Unix operating systems (and Solaris on SPARC architecture in particular) as discussed in class. Then state what parts of a C program are in each area. low memory Identify the following C constructs as either 1) Definition 2) Pure Declaration extern int x; int foo( int x ) return x; } struct fubar int x; } s1; float y; high memory struct fifi; extern int * func1( int x, float y ); When did you use the accessglobal() method in SymbolTable.java in Project 1? Using Reduced-C syntax, define a variable named fubaz that is an array of array of int such that fubaz[7][13] is a valid index expression indexing the last element in this array of array. This should take two lines of code. 6

Extra Credit What gets printed when the following C program is executed? #include <stdio.h> int main() char a[] = "Zach_and_Mo"; char *p = a; printf( "%c\n", *p++ ); printf( "%c\n", ++*p ); printf( "%c\n", *p = p[-1] - 1 ); printf( "%c\n", --*p++ ); printf( "%c\n", ++*p ); printf( "%c\n", --*++p ); printf( "%c\n", ++*(p+6) ); printf( "%d\n", p - a ); printf( "%s\n", a ); } return 0; A portion of the C Operator Precedence Table Operator Associativity ++ postfix increment L to R -- postfix decrement [] array element () function call -------------------------------------- * indirection R to L ++ prefix increment -- prefix decrement & address-of sizeof size of type/object (type) type cast -------------------------------------- * multiplication L to R / division % modulus -------------------------------------- + addition L to R - subtraction --------------------------------------.. -------------------------------------- = assignment R to L Hexadecimal - Character 00 NUL 01 SOH 02 STX 03 ETX 04 EOT 05 ENQ 06 ACK 07 BEL 08 BS 09 HT 0A NL 0B VT 0C NP 0D CR 0E SO 0F SI 10 DLE 11 DC1 12 DC2 13 DC3 14 DC4 15 NAK 16 SYN 17 ETB 18 CAN 19 EM 1A SUB 1B ESC 1C FS 1D GS 1E RS 1F US 20 SP 21! 22 " 23 # 24 $ 25 % 26 & 27 28 ( 29 ) 2A * 2B + 2C, 2D - 2E. 2F / 30 0 31 1 32 2 33 3 34 4 35 5 36 6 37 7 38 8 39 9 3A : 3B ; 3C < 3D = 3E > 3F? 40 @ 41 A 42 B 43 C 44 D 45 E 46 F 47 G 48 H 49 I 4A J 4B K 4C L 4D M 4E N 4F O 50 P 51 Q 52 R 53 S 54 T 55 U 56 V 57 W 58 X 59 Y 5A Z 5B [ 5C \ 5D ] 5E ^ 5F _ 60 61 a 62 b 63 c 64 d 65 e 66 f 67 g 68 h 69 i 6A j 6B k 6C l 6D m 6E n 6F o 70 p 71 q 72 r 73 s 74 t 75 u 76 v 77 w 78 x 79 y 7A z 7B 7C 7D } 7E ~ 7F DEL 7

Scratch Paper 8

Scratch Paper 9