Docsity

Midterm Exam CSE 30, Winter 2009 - Prof. Richard Ord, Exams of Computer Science

Toggle sidebar
bg1
1
Name _________________________
Student ID __________________ Signature_______________________
cs30x_______
CSE 30
Winter 2009
Midterm Exam
1. Number Systems ___________________ (15 points)
2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
3. Branching ___________________ (23 points)
4. Bit Operations / C Runtime Environment ___________________ (17 points)
5. Parameter Passing and Return Values (Stack Variables) ___________________ (12 points)
6. Local Variables, The Stack and Return Values ___________________ (16 points)
7. Load/Store/Memory ___________________ (11 points)
SubTotal ___________________ (106 points)
Extra Credit ___________________ (7 points)
Total ___________________
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Midterm Exam CSE 30, Winter 2009 - Prof. Richard Ord and more Exams Computer Science in PDF only on Docsity!

Name _________________________

Student ID __________________ Signature_______________________

cs30x_______

CSE 30

Winter 2009

Midterm Exam

1. Number Systems ___________________ (15 points)

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

3. Branching ___________________ (23 points)

4. Bit Operations / C Runtime Environment ___________________ (17 points)

5. Parameter Passing and Return Values (Stack Variables) ___________________ (12 points)

6. Local Variables, The Stack and Return Values ___________________ (16 points)

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

SubTotal ___________________ (106 points)

Extra Credit ___________________ (7 points)

Total ___________________

1. Number Systems

Convert 0xFC65 (2โ€™s complement, 16-bit word) to the following. (6 points)

binary ____________________________________ (straight base conversion)

octal 0 ___________________________________ (straight base conversion)

decimal ____________________________________ (convert to signed decimal)

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

sign-magnitude 0x_______________________________________________

1โ€™s complement 0x_______________________________________________

2โ€™s complement 0x_______________________________________________

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

sign-magnitude 0x_______________________________________________

1โ€™s complement 0x_______________________________________________

2โ€™s complement 0x_______________________________________________

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)

N Z V C N Z V C N Z V C

4. Bit Operations / C Runtime Environment

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

set 0x9375ACD1, %l

sra %l0, 15, %l

Value in %l0 is 0x_______________________________________ (2 points)

set 0x9375ACD1, %l

sll %l0, 9, %l

Value in %l0 is 0x_______________________________________ (2 points)

set 0x9375ACD1, %l

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

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

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

Fill in the names of the 5 areas of the C Runtime Environment as laid out by the SPARC architecture.

Then state what parts of a C program are in each area. (10 points)

low memory

__________________________________________________________

__________________________________________________________

__________________________________________________________

__________________________________________________________

__________________________________________________________

high memory

5. Parameter Passing and Return Values (Local Stack Struct Variable)

Write the equivalent unoptimized SPARC assembly language instructions to perform the following C code

fragment. You can assume just this one local variable. (12 points)

C SPARC assembly

/* Function Prototype */

short foo( char, int, unsigned short );

/* ... Other code ... */

/* Assume this local variable

is declared appropriately and is the only local var. */

struct fubar {

short a; char b[3]; int c; unsigned short d[2];

} fb; /* Local variable fb */

/* ... Other code ... */

/*

Write the code for just this Put your SPARC Assembly code function call, saving the in the box below. return value appropriately */

fb.a = foo( fb.b[2], fb.c, fb.d[0] );

7. 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 0xAA

.align 2 s: .half 0xFADE

.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 lduh [%l1], %l2 _____________________ Hex value in %l

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

srl %l2, 4, %l2 _____________________ Hex value in %l stb %l2, [%l0+1]

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 ldsb [%l1], %l2 _____________________ Hex value in %l

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

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

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

sra %l2, 12, %l2 _____________________ Hex value in %l sth %l2, [%l0+2]

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

ret restore

Extra Credit (7 points)

What gets printed at each printf() statement given the following C program?

#include <stdio.h>

int

main()

char a[] = "DAT30";

char *p = a;

printf( "%c", *p++ ); ______

printf( "%c", *(p+3) = *p); ______

printf( "%c", ++*p ); ______

printf( "%c", *++p ); ______

printf( "%c", ++*p++ ); ______

printf( "%d", ++p - a ); ______

printf( "\n%s\n", a ); _______________________

return 0;

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