Midterm CSE 131 Fall 2014

Similar documents
Midterm CSE 131 Winter 2015

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2013

Midterm CSE 131 Winter 2012

Final CSE 131 Fall 2014

Final CSE 131 Fall 2015

Final CSE 131 Winter 2012

Final CSE 131 Winter 2010

CSE 30 Fall 2012 Final Exam

CSE 30 Fall 2013 Final Exam

CSE 30 Winter 2014 Final Exam

Final CSE 131B Spring 2004

CSE 30 Winter 2009 Final Exam

Midterm CSE 131B Spring 2005

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2007 Final Exam

CSE 30 Spring 2006 Final Exam

CSE 30 Fall 2006 Final Exam

Final CSE 131B Spring 2005

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

Do not start the test until instructed to do so!

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/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

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

Chapter 2 Bits, Data Types, and Operations

Final Exam Practice Questions

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

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

Do not start the test until instructed to do so!

Chapter 8. Characters and Strings

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

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

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

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

Chapter 2 Bits, Data Types, and Operations

Fundamentals of Programming (C)

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

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

Number Representations

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

ASSIGNMENT 5 TIPS AND TRICKS

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

Chapter 2 Bits, Data Types, and Operations

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

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

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

The Binary Number System

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

Chapter 3. Information Representation

Oberon Data Types. Matteo Corti. December 5, 2001

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

Lecture (09) x86 programming 8

Simple Data Types in C. Alan L. Cox

CMPSC 311- Introduction to Systems Programming Module: Strings

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

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

User s Manual. Xi3000 Scanner. Table of Contents

Appendix A Developing a C Program on the UNIX system

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

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

Final CSE 131B Winter 2003

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

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

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

Chapter 2 Number System

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.

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

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.

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

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Number Systems Base r

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

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

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

2D BARCODE SCANNER CA-SC-20200B

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

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

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

Connecting UniOP to Datalogic Barcode Readers

Xi2000-BT Series Configuration Guide

Variables and data types

Question Points Score Total: 100

Data Representation and Storage. Some definitions (in C)

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

JAVA OPERATORS GENERAL

6.096 Introduction to C++ January (IAP) 2009

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any from ee209 yet Follow the link from our class homepage

Fundamentals of Programming

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

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

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

COS 226 Algorithms and Data Structures Fall Final

CSE 5A Final Fall 2006

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

Transcription:

Login Name _ Signature Name _ Student ID Midterm CSE 131 Fall 2014 Page 1 Page 2 Page 3 Page 4 Page 5 (35 points) (30 points) (24 points) (24 points) (32 points) Subtotal (145 points = 100%) Page 6 Extra Credit (16 points) 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 {: System.out.println("A"); :} T_ASSIGN Expr {: System.out.println("B"); :} Des {: System.out.println("C"); :} ; Des ::= T_STAR {: System.out.println("D"); :} Des {: System.out.println("E"); :} T_SIZEOF {: System.out.println("F"); :} T_LPAREN Des T_RPAREN {: System.out.println("G"); :} T_PLUSPLUS {: 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"); :} Des2 {: System.out.println("M"); :} T_LBRACKET Des T_RBRACKET {: System.out.println("N"); :} Des3 ; Des3 ::= T_ID ; What is the output when parsing the follow expression (you should have 22 lines/letters in your output) [22 pts]: Output q[ sizeof(r) ] = r[s] = ++*t++; In the above grammar, which has higher precedence: pointer dereference (i.e. *) or array dereference (i.e. []), or do they have the same precedence? [2 pts] _ In the above grammar, does the pointer dereference operator (i.e. *) have left-to-right or rightto-left associativity? [2 pts] _ If variable r is defined to be type float[5], what type must variables q, s and t be defined for this expression to be semantically correct? Define these variables to the minimum semantically-correct size using RC syntax. [9 pts] float[5] r; q; s; t; 1

2. Give the order of the typical GCC compilation stages and on to actual execution as discussed in class: [5 pts] 0 Source file (prog.c) 5 prog.exe/a.out (Executable image) 1 as (Assembler) 6 cpp (C preprocessor) 2 ld (Linkage Editor) 7 ccomp (C compiler) 3 Object file (prog.o) 8 Loader 4 Assembly file (prog.s) 9 Program Execution gcc: > > > > > > > > > Give the order of the general phases of compilation in a typical compiler as discussed in class: A Scanner (Lexical analysis) E Target language (e.g. assembly) B Parser (Semantic analysis/intermediate code gen.) F Target code generation C Machine-independent code improvement (optional) G Parser (Syntax analysis) D Machine-specific code improvement (optional) H Source language (e.g. C) [5pts] > > > > > > > Given the C array declaration C char * a[2][3]; Mark with an A all the memory location(s) where we would find the array element a[1][1]: [5 pts] a: low memory (Each box represents a byte in memory) high memory Given the following Reduced-C code structdef S1 { bool a; }; structdef S2 { bool a; }; typedef S1 S3; typedef S3 S4; S1 a, b; S2 c, d; S3 e; S4 f; identify each of the following statements as either: [15 pts] (A) No Error (B) Compile-Time Error a = b; c = d; a = (S1) c; a = c; c = e; a = * (S1*) &c; a = d; c = f; (S2) b = d; a = e; e = f; * (S2*) &b = d; a = f; a.a == b.a; f = e = b = a; 2

3. 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], p[1], p[2], etc. If the member/field is a struct, use the member name followed by its member names (e.g. p.a, p.b, etc.). Place an X in any bytes of padding. Structs/unions are padded so the total size is evenly divisible by the strictest alignment requirement of its members. [14 pts figure; 10 pts questions] struct foo { char a; double * b; }; struct bar { char c; double d; char e[5]; struct foo f; short g; }; struct bar baz; low memory baz: high memory What is the sizeof( struct bar )? _ What is the offsetof( struct bar, f.b )? _ If struct bar had been defined as union bar instead, what would be the sizeof( union bar )? _ If you rearrange the order of the struct members in struct bar to minimize padding, what would be the size of this modified struct bar? _ How many bytes are saved by rearranging the struct bar members to minimize padding? _ 3

4. Given the following pseudocode, determine the program output based on the specified scoping rule: [24 pts] int x; int y; -- global var declaration -- global var declaration void set_xy( int a, int b ) x = a; y = b; void beta() int y = 7; -- local var declaration set_xy( 5, 5 ); void alpha() int x = 2; -- local var declaration set_xy( 4, 4 ); beta(); set_xy( 0, 0 ); alpha(); What does the program output if the language uses static scoping? What does the program output if the language uses dynamic scoping? 4

5. 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. [10 pts] low memory _ high memory Given the following C code, indicate which of the 5 main areas of the C Runtime Environment (which you just described in the question above) each symbol is located in: [18 pts] int A, B; static int C, D = 1; int * E ( int F ) { static float G; int H = 3; int * I = (int *) malloc(sizeof(int)); A _ J _ B _ K _ C _ L _ D _ main _ return I; } E _ argc _ int main ( int argc, char *argv[] ) { F _ argv _ static int * J; J = E(1); G _ *J _ int * K = J; char L[50] = {0}; H _ *K _ free(j); *K = 1; I _ *L _ <------ determine runtime areas at this point in time return 0; } For the above program, while there are no compile-time errors, there is a serious programming mistake that can cause run-time crashes. Explain what the mistake is: [4 pts] 5

Extra Credit What gets printed when the following C program is executed? [16 pts] #include <stdio.h> int main() { char a[] = "MALLOC"; char *p = a; printf( "%c\n", *p++ ); printf( "%c\n", (*p++ = 1[a] + 5) 1 ); printf( "%c\n", *p++ = *a ); printf( "%c\n", (*p = *(p + 1) = (*p 7)) + 10 ); printf( "%c\n", *--p = (*a + 5) ); printf( "%c\n", *p + 7 ); printf( "%c\n", *(p 2) = *(p + 3) =! ); 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 6

Scratch Paper 7