






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 10
This page cannot be seen from the preview
Don't miss anything!







**1. Number Systems ___________________ (15 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 */