Docsity

Final Exam - Computer Organization and Systems Program - Spring 2008 | CSE 30, Exams of Computer Science

Toggle sidebar
bg1
1
Login: cs30x_______
Name _________________________
Student ID ____________________ Signature_______________________
CSE 30
Spring 2008
Final Exam
1. Number Systems / C Compiling Sequence ___________________ (26 points)
2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
3. Branching ___________________ (19 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 ___________________ (12 points)
8. Floating Point ___________________ (12 points)
9. Machine Instructions ___________________ (20 points)
10. Linkage, Scope, Lifetime, Data ___________________ (32 points)
11. Load/Store/Memory ___________________ (11 points)
12. Miscellaneous ___________________ (29 points)
SubTotal ___________________ (216 points)
Extra Credit ___________________ (13 points)
Total ___________________
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Final Exam - Computer Organization and Systems Program - Spring 2008 | CSE 30 and more Exams Computer Science in PDF only on Docsity!

Login: cs30x_______ Name _________________________

Student ID ____________________ Signature_______________________

CSE 30

Spring 2008

Final Exam

1. Number Systems / C Compiling Sequence ___________________ (26 points)

2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)

3. Branching ___________________ (19 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 ___________________ (12 points)

8. Floating Point ___________________ (12 points)

9. Machine Instructions ___________________ (20 points)

10. Linkage, Scope, Lifetime, Data ___________________ (32 points)

11. Load/Store/Memory ___________________ (11 points)

12. Miscellaneous ___________________ (29 points)

SubTotal ___________________ (216 points)

Extra Credit ___________________ (13 points)

Total ___________________

1. Number Systems

Convert FBC2 16 (2’s complement, 16-bit word) to the following. (6 points)

binary_____________________________________ (straight base conversion)

octal_______________________________________ (straight base conversion)

decimal____________________________________ (convert to signed decimal)

Convert 48210 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points)

sign-magnitude_______________________________________________

1’s complement_______________________________________________

2’s complement_______________________________________________

Convert -329 10 to the following (assume 16-bit word). Express answers in hexadecimal. (6 points)

sign-magnitude_______________________________________________

1’s complement_______________________________________________

2’s complement_______________________________________________

C Compiling Sequence

Put the following in the correct order/sequence using the letters to the left of each word: (11 points)

A. C source code (.c file) B. linkage editor C. resulting .o file

D. loader E. program execution F. resulting .s file

G. executable (.exe/a.out) H. assembler I. segmentation fault/core dump

J. C compiler K. C preprocessor

____ —> ____ —> ____ —> ____ —> ____ —> ____ —> ____ —> ____ —> ____ —> ____ —> ____

4. Bit Operations

What is the value of %l0 after each statement is executed? Express your answers in hexadecimal.

set 0xBEADFACE, %l

set 0x87654321, %l

or %l0, %l1, %l

Value in %l0 is _______________________________________ (2 points)

set 0xBEADFACE, %l

sra %l0, 9, %l

Value in %l0 is _______________________________________ (2 points)

set 0xBEADFACE, %l

sll %l0, 14, %l

Value in %l0 is _______________________________________ (2 points)

set 0xBEADFACE, %l

set 0x????????, %l

xor %l0, %l1, %l0! Value in %l0 is now OxCAFEBABE

Value set in %l1 must be this bit pattern _______________________________________ (3 points)

set 0xBEADFACE, %l

set 0x87654321, %l

and %l0, %l1, %l

Value in %l0 is _______________________________________ (2 points)

set 0xBEADFACE, %l

srl %l0, 10, %l

Value in %l0 is _______________________________________ (2 points)

5. Recursion/SPARC Assembly

Given main.s and fubar.s, what gets printed when executed? (10 points)

.global main /* main.s */

.section ".rodata"

.align 4 code: .word 0x65766950, 0x65676146, 0x00336E4A, 0x306F2020, 0x4C3E5220, 0x .word 0x6C760065, 0x6900734C, 0x

.section ".text" main: save %sp, -92 & -8, %sp

set code, %o mov 0, %o call fubar nop

ret restore

.global fubar /* fubar.s */

.section ".rodata" fmt: .asciz "%c"

.section ".text" fubar: save %sp, -(92 + 1) & -8, %sp

andcc %i1, 0x01, %g bne L nop

add %i1, 3, %l ba L nop

L1:

add %i1, 5, %l

L2: and %l0, 0x07, %l

ldub [%i0 + %l0], %l stb %l1, [%fp - 1]

cmp %l0, 0x be end nop

add %i1, 1, %o mov %i0, %o call fubar nop

end: set fmt, %o ldub [%fp - 1], %o call printf nop

ret restore

What gets printed? ________________________

7. More Recursive Subroutines / Drawing Stack Frames

What is the output of the following program? (12 pts)

#include <stdio.h>

int AAA( int a ) { int result1;

printf( "a = %d\n", a );

if ( a >= 10 ) return 1; else { result1 = (BBB( a + 1 ) + a); printf( "result1 = %d\n", result1 ); return result1; } }

int BBB( int b ) { int result2;

printf( "b = %d\n", b );

if ( b >= 10 ) return 3; else { result2 = (AAA( b + 3 ) + b); printf( "result2 = %d\n", result2 ); return result2; } }

int main( int argc, char *argv[] ) { printf( "%d\n", BBB( 1 ) );

return 0; }

Put output here

8. Floating Point

Convert 146.75 10 (decimal fixed-point) to binary fixed-point (binary) and single-precision IEEE floating-point

(hexadecimal) representations.

binary fixed-point __________________________________ (2 points)

IEEE floating-point __________________________________ (4 points)

Convert 0xC342E000 (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 number of instructions away for the target (vs. a Label).

andcc %o4, 0x17, %i4 ___________________________________ (5 points)

std %l6, [%fp + %o1] ___________________________________ (5 points)

Translate the following SPARC machine code instructions into SPARC assembly instructions.

0x3c800011 ___________________________________ (5 points)

0x9a868012 ___________________________________ (5 points)

11. Load/Store/Memory

Specify the hex values requested after those lines have been fully executed. (11 points)

.global main

.section ".data" fmt: .asciz "0x%08X\n"! prints value as hex 0xXXXXXXXX

c: .byte 0xBB

.align 2 s: .half 0xCAFE

.align 4 i1: .word 0x i2: .word 0x i3: .word 0x x: .word 0x

.section ".text" main: save %sp, -96, %sp

set x, %l set s, %l ldsh [%l1], %l2 _____________________ Hex value in %l

stb %l2, [%l0+1] _____________________ Hex value in word labeled x

srl %l2, 12, %l2 _____________________ Hex value in %l stb %l2, [%l0+3]

set fmt, %o ld [%l0], %o call printf _____________________ Hex value in word labeled x nop (same as output of this printf)

set i1, %l set c, %l ldub [%l1], %l2 _____________________ Hex value in %l

sth %l2, [%l0+2] _____________________ Hex value in word labeled i stb %l2, [%l0]

set fmt, %o ld [%l0], %o call printf _____________________ Hex value in word labeled i nop (same as output of this printf)

set i2, %l set i3, %l ld [%l1], %l2 _____________________ Hex value in %l

sth %l2, [%l0] _____________________ Hex value in word labeled i

sra %l2, 16, %l2 _____________________ Hex value in %l stb %l2, [%l0+1]

set fmt, %o ld [%l0], %o call printf _____________________ Hex value in word labeled i nop (same as output of this printf)

ret restore

12. Miscellaneous

What is the output of the following program? (8 points)

#include <stdio.h> #define SIZE 4 void mystery( unsigned short hwords[], size_t size );

int main() { int i; unsigned short hwords[SIZE] = { 0x1942, 0xF837, 0x13AC, 0xB6D5 }; mystery( hwords, SIZE ); for ( i = 0; i < SIZE; ++i ) { printf( "0x%04X ", hwords[i] ); /* Prints 0xXXXX */ } putchar( '\n' ); return 0; }

void mystery( unsigned short hwords[], size_t size ) { int i; for ( i = 0; i < size/2; ++i ) { hwords[i] = hwords[i] ^ hwords[i + 2]; hwords[i + 2] = hwords[i + 2] ^ hwords[i]; hwords[i] = hwords[i] ^ hwords[i + 2]; } }

If Rick had a dog, what would it's name be? (1 pt) ________________________________________________

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 value to largest value. (2 points each)

void foo( int, int ); /* Function Prototype */ int a = 24;

int main( int argc, char *argv[] ) {

int b = 99; prints int c; ___________ smallest value

foo( c, b ); ___________

/* 1 / (void) printf( "c --> %p\n", &c ); ___________ / 2 / (void) printf( "foo --> %p\n", foo ); / 3 / (void) printf( "b --> %p\n", &b ); ___________ / 4 / (void) printf( "argc --> %p\n", &argc ); / 5 */ (void) printf( "malloc --> %p\n", malloc(50) ); ___________ }


void foo( int d, int e ) {


int f = 42; static int g; ___________

/* 6 / (void) printf( "g --> %p\n", &g ); ___________ / 7 / (void) printf( "e --> %p\n", &e ); / 8 / (void) printf( "a --> %p\n", &a ); ___________ prints / 9 / (void) printf( "f --> %p\n", &f ); largest value / 10 */ (void) printf( "d --> %p\n", &d ); }

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 / |

| 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

* indirection R to L

++ prefix increment

-- prefix decrement

& address-of

* multiplication L to R

/ division

% modulus

+ addition L to R

  • subtraction

= assignment R to L

Scratch Paper