CSE 30 Winter 2014 Final Exam

Similar documents
CSE 30 Fall 2013 Final Exam

CSE 30 Fall 2012 Final Exam

CSE 30 Winter 2009 Final Exam

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2007 Final Exam

CSE 30 Spring 2006 Final Exam

CSE 30 Fall 2006 Final Exam

Midterm CSE 131 Winter 2012

Final CSE 131 Winter 2012

Midterm CSE 131 Fall 2014

Midterm CSE 131 Winter 2013

Final CSE 131 Winter 2010

Midterm CSE 131 Winter 2014

Final CSE 131 Fall 2014

Final CSE 131 Fall 2015

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 Winter 2003

Final CSE 131B Spring 2005

Data Representation and Binary Arithmetic. Lecture 2

Fundamentals of Programming (C)

Do not start the test until instructed to do so!

Number Representations

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 Number System

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!

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

Chapter 2 Bits, Data Types, and Operations

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

Chapter 2 Bits, Data Types, and Operations

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

The Binary Number System

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.

Chapter 3. Information Representation

Chapter 2 Bits, Data Types, and Operations

Fundamentals of Programming

Oberon Data Types. Matteo Corti. December 5, 2001

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

ASSIGNMENT 5 TIPS AND TRICKS

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

Chapter 2 Bits, Data Types, and Operations

Number Systems Base r

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

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?

Chapter 2 Bits, Data Types, and Operations

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

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

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Chapter 8. Characters and Strings

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

Midterm CSE 131B Spring 2005

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

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

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

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

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

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

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

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

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

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

Appendix A Developing a C Program on the UNIX system

231 Spring Final Exam Name:

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

EE 109 Unit 2. Binary Representation Systems

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

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

Simple Data Types in C. Alan L. Cox

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

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

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

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

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

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

Lecture (09) x86 programming 8

3.1. Unit 3. 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

Question Points Score Total: 100

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

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

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

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

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

Source coding and compression

Fundamental Data Types

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

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.

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems

CMPSC 311- Introduction to Systems Programming Module: Strings

Positional Number System

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

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

Transcription:

Signature Login: cs30x Name Student ID 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 Winter 2014 Final Exam 1. Number Systems / Right-Left Rule _ (21 points) 2. Binary Addition/Condition Code Bits/Overflow Detection _ (12 points) 3. Branching _ (18 points) 4. Bit Operations _ (13 points) 5. Recursion/SPARC Assembly _ (10 points) 6. Local Variables, The Stack, Return Values _ (18 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 _ (201 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 0xFAE8 (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 284 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points) sign-magnitude 1 s complement 2 s complement Convert -659 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 foobar that is a pointer to an array of 17 elements where each element is a pointer to a function that takes a pointer to a struct foo and returns a pointer to a double. (6 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) 11010110 00110100 00011101 +10111011 +01001100 +00101001 --------- --------- --------- N Z V C N Z V C N Z V C ----------------- ----------------- ----------------- ----------------- ----------------- ----------------- 2

3. Branching (18 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. This is not an entire function - just translate the code fragment using the local register mapping indicated. _C SPARC ASSEMBLY_ /* Assume variables a and b have been! a is mapped to %l2 properly declared as ints. */! b is mapped to %l5 /* Some other code here */ /* Translate just this code below */ if ( a > b ) do a = a % b; while ( a >= 55 ); --b; else b = b + 44; /* Some other code here */ 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 0xDEADC0DE, %l0 set 0x86715309, %l1 and %l0, %l1, %l0 Value in %l0 is (2 points) set 0xDEADC0DE, %l0 sra %l0, 7, %l0 Value in %l0 is (2 points) set 0xDEADC0DE, %l0 sll %l0, 7, %l0 Value in %l0 is (2 points) set 0xDEADC0DE, %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 0xDEADC0DE, %l0 set 0x86715309, %l1 or %l0, %l1, %l0 Value in %l0 is (2 points) set 0xDEADC0DE, %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 0x3E736463, 0x72656D74, 0x6B445061, 0x2F3D4E32, 0x2B206B2B, 0x666B4372.word 0x602F7545, 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 inc %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 char fubar( int a, char b ) int local_stack_var1; int *local_stack_var2; struct foo int s1; int s2[3]; char s3[3]; char s4; 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. Keep the formal parameters a and b in their incoming registers. local_stack_var3.s4 = ++b; /* 1 */ local_stack_var1 = ++*local_stack_var2; /* 2 */ local_stack_var3.s1 = local_stack_var3.s2[0] + a++; /* 3 */ return ( local_stack_var3.s3[2] ); /* 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. (18 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 ); // output: x1 = if ( x1 <= 1 ) return 1; else r1 = BBB( x1-2 ) + x1; printf( "r1 = %d\n", r1 ); // output: r1 = return r1; int BBB( int x2 ) int r2; printf( "x2 = %d\n", x2 ); // output: x2 = if ( x2 <= 2 ) return 2; else r2 = AAA( x2-1 ) + x2; printf( "r2 = %d\n", r2 ); // output: r2 = return r2; int main( int argc, char *argv[] ) // output value returned by // initial call printf( "%d\n", AAA( 5 ) ); Put output here return 0; 7

8. Floating Point Convert -139.25 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 0x43356000 (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). addcc %l3, -9, %i2 (5 points) sth %o2, [%i3 + %l1] (5 points) Translate the following SPARC machine code instructions into SPARC assembly instructions. 0x2E800008 0xAC1AC019 (5 points) (5 points) If an odd-ball computer had 121MB 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) static int a; ( a ) int b = 42; ( b ) int c; ( c ) static int d = 11; ( d ) static int foo( int e ) ( e ) ( foo ) float f = 42.24; ( f ) char *g; ( g ) g = (char *) malloc( b ); (where g is pointing) static int (*h)(int) = foo; ( h ) (where h is pointing) static double i; ( 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 5 times, indicate how many times will f be initialized? If the function foo() above is called 5 times, indicate how many times will h 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 0x99.align 2 s:.half 0xFACE.align 4 i1:.word 0x9ABCD123 i2:.word 0x9ABCD123 i3:.word 0x9ABCD123 x:.word 0x55550000 main:.section ".text" save %sp, -96, %sp set x, %l0 set s, %l1 lduh [%l1], %l2 Hex value in %l2 stb %l2, [%l0+3] Hex value in word labeled x srl %l2, 4, %l2 Hex value in %l2 stb %l2, [%l0+1] 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+3] 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+1] 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 What value must input D and E be in order to set output Q to the value 0 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 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 below - answer one of A-F) Complete the truth table for the following logic diagram: A B C 0 0 0 1 1 0 A) 0 B) 1 C) Either 0 or 1 A) Tri-State Logic Circuit B) Combinational Logic Circuit C) Bi-Modal Logic Circuit D) Synchronous Sequential Logic Circuit E) De Morgan Logic Circuit F) Asynchronous Sequential 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!) 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 */ static int a; int main( int argc, char *argv[] ) int b = 7; static int c = 11; foo( argc, c ); /* 1 */ (void) printf( "1: argc --> %p\n", &argc ); /* 2 */ (void) printf( "2: malloc --> %p\n", malloc(50) ); /* 3 */ (void) printf( "3: foo --> %p\n", foo ); /* 4 */ (void) printf( "4: b --> %p\n", &b ); /* 5 */ (void) printf( "5: c --> %p\n", &c ); void foo( int d, int e ) int f = 5; int g; /* 6 */ (void) printf( "6: g --> %p\n", &g ); /* 7 */ (void) printf( "7: a --> %p\n", &a ); /* 8 */ (void) printf( "8: e --> %p\n", &e ); /* 9 */ (void) printf( "9: d --> %p\n", &d ); /* 10 */ (void) printf( "10: f --> %p\n", &f ); 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[] = "CSE30"; 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[2][1] low memory high memory Each box represents a byte in memory. What is Rick's favorite Disney movie? 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