CSE 30 Fall 2013 Final Exam

Similar documents
CSE 30 Winter 2014 Final Exam

CSE 30 Fall 2012 Final Exam

CSE 30 Winter 2009 Final Exam

CSE 30 Spring 2006 Final Exam

CSE 30 Fall 2007 Final Exam

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2006 Final Exam

Midterm CSE 131 Winter 2012

Midterm CSE 131 Fall 2014

Final CSE 131 Fall 2014

Final CSE 131 Winter 2012

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2013

Final CSE 131 Fall 2015

Final CSE 131 Winter 2010

Midterm CSE 131 Winter 2015

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

Final CSE 131B Spring 2004

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

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

Final CSE 131B Spring 2005

Fundamentals of Programming (C)

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!

Final CSE 131B Winter 2003

Chapter 2 Number System

Number Representations

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

Chapter 2 Bits, Data Types, and Operations

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

Do not start the test until instructed to do so!

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

Chapter 2 Bits, Data Types, and Operations

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

Chapter 3. Information Representation

Oberon Data Types. Matteo Corti. December 5, 2001

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

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.

ASSIGNMENT 5 TIPS AND TRICKS

Fundamentals of Programming

The Binary Number System

Number Systems Base r

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations

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

Chapter 8. Characters and Strings

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

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

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

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

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

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

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

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

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

Midterm CSE 131B Spring 2005

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

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

Appendix A Developing a C Program on the UNIX system

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

Number System (Different Ways To Say How Many) Fall 2016

Simple Data Types in C. Alan L. Cox

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

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

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

Introduction to Computer Engineering. CS/ECE 252, Spring 2017 Rahul Nayar Computer Sciences Department University of Wisconsin Madison

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

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

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

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

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

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

EE 109 Unit 2. Binary Representation Systems

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

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

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

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

231 Spring Final Exam Name:

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

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

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.

Question Points Score Total: 100

Compiler Design. Homework 1. Due Date: Thursday, January 19, 2006, 2:00

Lecture (09) x86 programming 8

CMPSC 311- Introduction to Systems Programming Module: Strings

Positional Number System

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

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

3.1. Unit 3. Binary Representation

UNIVERSITY OF LIMERICK OLLSCOIL LUIMNIGH COLLEGE OF INFORMATICS & ELECTRONICS DEPARTMENT OF ELECTRONIC & COMPUTER ENGINEERING

Practical Malware Analysis

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

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

RS-232 Control of the Advantage DRI

Hardware. ( Not so hard really )

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Transcription:

Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship. CSE 30 Fall 2013 Final Exam 1. Number Systems / Right-Left Rule _ (22 points) 2. Binary Addition/Condition Code Bits/Overflow Detection _ (12 points) 3. Branching _ (21 points) 4. Bit Operations _ (13 points) 5. Recursion/SPARC Assembly _ (10 points) 6. Local Variables, The Stack, Return Values _ (20 points) 7. More Recursive Subroutines _ (8 points) 8. Floating Point _ (12 points) 9. Machine Instructions _ (21 points) 10. Linkage, Scope, Lifetime, Data _ (34 points) 11. Load/Store/Memory _ (11 points) 12. Miscellaneous _ (23 points) SubTotal Extra Credit (~5%) Total _ (207 points) _ (10 points) _ This exam is to be taken by yourself with closed books, closed notes, no electronic devices. You are allowed both sides of an 8.5"x11" sheet of paper handwritten by you. 1

1. Number Systems Convert 0xFB8E (2 s complement, 16-bit word) to the following. (6 points) binary_ (straight base conversion to binary) octal (straight base conversion) decimal (convert to signed decimal) Convert 274 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points) sign-magnitude 1 s complement 2 s complement Convert -695 to the following (assume 16-bit word). Express answers in hexadecimal. (6 points) sign-magnitude 1 s complement 2 s complement Rt-Lt Rule Using the C Rt-Lt Rule, define a variable named fubar that is a multi-dimensional array of 17 rows and 35 columns where each element is a pointer to a function that takes a single argument of type pointer to double and returns a pointer to an array of 23 elements where each element is of type pointer to struct foobar. (7 points) 2. Binary Addition/Condition Code Bits/Overflow Detection Indicate what the condition code bits are when adding the following 8-bit 2 s complement numbers. (12 points) 01010110 10110100 10011101 +00111011 +01001100 +10101001 --------- --------- --------- N Z V C N Z V C N Z V C ----------------- ----------------- ----------------- ----------------- ----------------- ----------------- 2

3. Branching (21 points) Translate the C code below into the equivalent utimized SPARC Assembly code. Just perform a direct translation no optimizations. Use the local register mappings for the variables in assembly as specified. Remember to implement short-circuiting logic for the logical OR. _C SPARC ASSEMBLY_ /* Assume variables a and b have been! a is mapped to %l3 properly declared as ints. */! b is mapped to %l6 if ( (a <= b) (b > 99) ) do a = a * b; while ( a < 55 ); ++b; else b = b - 22; 3

4. Bit Operations What is the value of %l0 after each statement is executed? Express your answers as 8 hexadecimal digits. (All 32 bits. Be sure to specify any leading or trailing zeros.) set 0xFEEDBABE, %l0 set 0x86715309, %l1 and %l0, %l1, %l0 Value in %l0 is (2 points) set 0xFEEDBABE, %l0 sra %l0, 7, %l0 Value in %l0 is (2 points) set 0xFEEDBABE, %l0 sll %l0, 7, %l0 Value in %l0 is (2 points) set 0xFEEDBABE, %l0 set 0x????????, %l1 xor %l0, %l1, %l0! Value in %l0 is now Ox86715309 Value set in %l1 must be this bit pattern (3 points) set 0xFEEDBABE, %l0 set 0x86715309, %l1 or %l0, %l1, %l0 Value in %l0 is (2 points) set 0xFEEDBABE, %l0 srl %l0, 6, %l0 Value in %l0 is (2 points) 4

5. Recursion/SPARC Assembly Given main.s and fubar.s, what gets printed when executed? Yes Draw stack frames! (10 points).global main /* main.s */.section ".rodata".align 4.word 0x30003300 code:.word 0x33736447, 0x72657074, 0x6B735061, 0x663D4E37, 0x2B20422B, 0x66754372.word 0x662F7522, 0x43537300, 0x00000030 main:.section ".text" save %sp, -92 & -8, %sp set code, %o0 mov 27, %o1 call fubar ret restore.global fubar /* fubar.s */ fmt: fubar:.section ".rodata".asciz "%c".section ".text" save %sp, -(92 + 1) & -8, %sp cmp %i0, %g0 be end ldub [%i0 + %i1], %l0 cmp %l0, %g0 be end dec %l0 stb %l0, [%fp - 1] sub %i1, 3, %o1 mov %i0, %o0 call fubar set fmt, %o0 ldub [%fp - 1], %o1 call printf end: ret restore What gets printed? _ 5

6. Local Variables, The Stack, and Return Values Here is a C function that allocates a few local variables, performs some assignments and returns a value. Don t worry about any local variables not being initialized before being used. Just do a direct translation. Draw lines. C int fubar( int a, char b ) int *local_stack_var1; int local_stack_var2; struct foo int s1[3]; char s2; int s3; char s4[8]; local_stack_var3; Draw a line between each group of assembly statements representing each C statement and label them 1, 2, 3, or 4 appropriately. local_stack_var3.s4[3] = 'A'; /* 1 */ local_stack_var2 = b++ + local_stack_var3.s1[2]; /* 2 */ local_stack_var3.s2 = local_stack_var3.s4[1] - a; /* 3 */ return ( ++*local_stack_var1 + 420 ); /* 4 */ Write the equivalent full utimized SPARC assembly language module to perform the equivalent. You must allocate all local variables on the stack. No short cuts. Treat each statement independently. (20 points) 6

7. More Recursive Subroutines / Drawing Stack Frames What is the output of the following program? (8 pts) #include <stdio.h> int AAA( int x1 ) int r1; printf( "x1 = %d\n", x1 ); if ( x1 <= 1 ) return 1; else r1 = BBB( x1-1 ) + x1; printf( "r1 = %d\n", r1 ); return r1; int BBB( int x2 ) int r2; printf( "x2 = %d\n", x2 ); if ( x2 <= 2 ) return 2; else r2 = AAA( x2-2 ) + x2; printf( "r2 = %d\n", r2 ); return r2; int main( int argc, char *argv[] ) printf( "%d\n", BBB( 6 ) ); Put output here return 0; 7

8. Floating Point Convert 139.75 10 (decimal fixed-point) to binary fixed-point (binary) and single-precision IEEE floating-point (hexadecimal) representations. binary fixed-point IEEE floating-point (2 points) (4 points) Convert 0xC335E000 (single-precision IEEE floating-point representation) to fixed-point decimal. fixed-point decimal (6 points) 9. Machine Instructions Translate the following instructions into SPARC machine code. Use hexadecimal values for your answers. If an instruction is a branch, specify the + or - number of instructions away for the target (vs. a Label). xorcc %o2, %l5, %i1 (5 points) sth %i4, [%l3 + 12] (5 points) Translate the following SPARC machine code instructions into SPARC assembly instructions. 0x36800011 0xA882FFF4 (5 points) (5 points) If an odd-ball computer had 421MB of memory, how many bits would be needed in an address register to address any byte in this system? (1 point) 8

10. Linkage, Scope, Lifetime, Data For the following program fragment, specify in which C runtime area/segment each symbol will be allocated or pointing: (34 points 1 point each) int a = -17; ( a ) static int b; ( b ) static int c = 37; ( c ) int d; ( d ) int foo( int e ) ( e ) ( foo ) static double f = 42.24; ( f ) static int *g; ( g ) g = (int *) malloc( e ); int (*h)(int) = foo; ( h ) (where g is pointing) (where h is pointing) double i = f; ( i )... Fill in the letter corresponding to the correct Fill in the letter corresponding to the correct scoping/visibility for each of the variables: lifetime for each of the variables: A) Global across all modules/functions A) Exists from the time the program is loaded to linked with this source file (global scope). the point when the program terminates. B) Global just to this source file (file scope). B) Exists from the time function foo() is called to C) Local to function foo() (local/block scope). the point when foo() returns. a a b b c c d d e e f f g g h h i i foo foo If the function foo() above is called 10 times, indicate how many times will f be initialized? If the function foo() above is called 10 times, indicate how many times will i be initialized? 9

11. Load/Store/Memory Specify the all 8 hex values requested after those lines have been fully executed. (11 points) (All 32 bits. Be sure to specify any leading or trailing zeros.).global main.section ".data" fmt:.asciz "0x%08X\n"! prints value as hex 0xXXXXXXXX c:.byte 0xDD.align 2 s:.half 0xCAFE.align 4 i1:.word 0x13579BDF i2:.word 0x13579BDF i3:.word 0x13579BDF x:.word 0x87650000 main:.section ".text" save %sp, -96, %sp set x, %l0 set s, %l1 ldsh [%l1], %l2 Hex value in %l2 stb %l2, [%l0+2] Hex value in word labeled x srl %l2, 4, %l2 _ Hex value in %l2 sth %l2, [%l0] set fmt, %o0 ld [%l0], %o1 call printf _ Hex value in word labeled x (same as output of this printf) set i1, %l0 set c, %l1 ldsb [%l1], %l2 _ Hex value in %l2 sth %l2, [%l0] _ Hex value in word labeled i1 stb %l2, [%l0] set fmt, %o0 ld [%l0], %o1 call printf _ Hex value in word labeled i1 (same as output of this printf) set i2, %l0 set i3, %l1 ld [%l1], %l2 _ Hex value in %l2 stb %l2, [%l0] _ Hex value in word labeled i2 sra %l2, 12, %l2 _ Hex value in %l2 sth %l2, [%l0+2] set fmt, %o0 ld [%l0], %o1 call printf _ Hex value in word labeled i2 (same as output of this printf) ret restore 10

12. Miscellaneous Complete the truth table for the following logic diagram: A B X 0 0 0 1 1 0 A) Combinational Logic Circuit B) Synchronous Sequential Logic Circuit C) Asynchronous Sequential Logic Circuit D) Tri-State Logic Circuit E) Bi-Modal Logic Circuit F) De Morgan Logic Circuit 1 1 What kind of logic circuit is this? (From table above - answer one of A-F) Draw the logic circuit for the following boolean expression expressed with C bitwise operators: (a ^ b) ~(c & d) (Use 3 logic gates - Do not use inverters in the logic diagram!) What value must input D and E be in order to set output Q to the value 1 independent of what value Q may have been previously? Use the letters in the box below to answer this and the next question. D E A) 0 B) 1 C) Either 0 or 1 What value of E will keep the output Q the same independent of what value D is? What kind of logic circuit is this? (From table above - answer one of A-F) Given the following program, order the printf() lines so that the values that are printed when run on a Sun SPARC Unix system are displayed from smallest address/value to largest address/value. #include <stdio.h> #include <stdlib.h> void foo( int, int ); /* Function Prototype */ int a = 24; int main( int argc, char *argv[] ) int b = 99; int c; foo( c, b ); /* 1 */ (void) printf( "1: c --> %p\n", &c ); /* 2 */ (void) printf( "2: foo --> %p\n", foo ); /* 3 */ (void) printf( "3: b --> %p\n", &b ); /* 4 */ (void) printf( "4: argc --> %p\n", &argc ); /* 5 */ (void) printf( "5: malloc --> %p\n", malloc(50) ); void foo( int d, int e ) int f = 42; static int g; /* 6 */ (void) printf( "6: g --> %p\n", &g ); /* 7 */ (void) printf( "7: e --> %p\n", &e ); /* 8 */ (void) printf( "8: a --> %p\n", &a ); /* 9 */ (void) printf( "9: f --> %p\n", &f ); /* 10 */ (void) printf( "10: d --> %p\n", &d ); this line prints smallest value this line prints largest value 11

Extra Credit (10 points) What is the value of each of the following expressions taken sequentially based on changes that may have been made in previous statements? #include <stdio.h> int main() char a[] = "10019"; char *ptr = a; printf( "%c\n", *ptr++ ); printf( "%c\n", (*ptr)++ ); printf( "%c\n", ++*ptr ); printf( "%c\n", ++*ptr++ ); printf( "%c\n", ++*ptr ); printf( "%c\n", --*++ptr ); printf( "%d\n", ptr - a ); printf( "%s\n", a ); return 0; Given the C array declaration C int a[4][2]; Mark with an A the memory location(s) where we would find a: a[3][0] low memory high memory Each box represents a byte in memory. What is the color of Rick's eyes? 12

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 A portion of the Operator Precedence Table Operator Associativity ++ postfix increment L to R -- postfix decrement [] array element () function call -> struct/union pointer. struct/union member -------------------------------------- * 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 13

Scratch Paper 14

Scratch Paper 15