CS30 Midterm Exam Fall 2005 - CSE 30 - Prof. Richard Ord, Exams of Computer Science

The cs30 midterm exam for the cse 30 course during the fall 2005 semester. The exam covers various topics in computer science, including number systems, binary addition, branching, bit operations, parameter passing, local variables, and load/store operations.

Typology: Exams

Pre 2010

Uploaded on 03/28/2010

koofers-user-z67
koofers-user-z67 🇺🇸

5

(1)

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

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

Partial preview of the text

Download CS30 Midterm Exam Fall 2005 - CSE 30 - Prof. Richard Ord and more Exams Computer Science in PDF only on Docsity!

Name _________________________

Student ID __________________ Signature_______________________

cs30x_______

CSE 30

Fall 2005

Midterm Exam

**1. Number Systems ___________________ (15 points)

  1. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
  2. Branching ___________________ (20 points)
  3. Bit Operations / C Runtime Environment ___________________ (17 points)
  4. Parameter Passing and Return Values (Structures) ___________________ (12 points)
  5. Local Variables, The Stack, and Return Values ___________________ (15 points)
  6. Load/Store/Memory ___________________ (9 points)**

SubTotal ___________________ (100 points)

Extra Credit ___________________ (5 points)

Total ___________________

1. Number Systems

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

binary ____________________________________

octal 0 ___________________________________

decimal ____________________________________

Convert -326 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 +435 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)

01010111 11010110 10111011 +00101001 +10111001 +


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 0x98ACED76, %l sra %l0, 13, %l

Value in %l0 is 0x _______________________________________ (2 points)

set 0x98ACED76, %l sll %l0, 11, %l

Value in %l0 is 0x _______________________________________ (2 points)

set 0x98ACED76, %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 (Structures)

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, unsigned short, char );

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

/* Assume this local variable is declared appropriately and is the only local var. */

struct fubar { char a; int b; short c[3]; char d[3]; unsigned short e; } fb; /* Local variable fb */

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

/ Write the code for just this function call saving the return value appropriately /

fb.c[1] = foo( fb.a, fb.e, fb.d[2] );

7. Load/Store/Memory What gets printed in the following program? (9 points)

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

c: .byte 0xDD

.align 2 s: .half 0x

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

.section ".text" main: save %sp, -96, %sp set i1, %l set s, %l ldsb [%l1+1], %l sth %l1, [%l0+2] set fmt, %o ld [%l0], %o call printf _________________________________ nop set i2, %l set c, %l ldub [%l1], %l stb %l1, [%l0+1] set fmt, %o ld [%l0], %o call printf _________________________________ nop set i3, %l set x, %l ldub [%l0+2], %l stb %l2, [%l1+2] ldsh [%l0+2], %l sth %l2, [%l1] mov %l1, %l set fmt, %o ld [%l0], %o1 _________________________________ call printf nop ret restore

Extra Credit (5 points)

Optimize the following SPARC Assembly code fragment. You can assume there are other instructions above and below this code fragment, but only optimize using the instructions given in this code fragment. Some optimizations may be worth more than others.

Unoptimized SPARC Assembly Optimized SPARC Assembly

/* Other code you cannot use */

cmp %i2, %l bg end_loop nop

loop: add %i2, %i0, %i mov 32, %o mov %i2, %o call .mul nop mov %o0, %i cmp %i2, %l ble loop nop

end_loop: inc %i

/* Other code you cannot use */

Scratch Paper