






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
A midterm exam for the cse 30 course in computer science, held in winter 2006. The exam covers various topics in computer organization, 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 0xF933 (2’s complement, 16-bit word) to the following. (6 points)
binary ____________________________________
octal 0 ___________________________________
decimal ____________________________________
Convert -316 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 +485 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 10000101 11111111 +00001001 +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 0x8A8B1112, %l sra %l0, 13, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0x8A8B1112, %l sll %l0, 11, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0x8A8B1112, %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 */
int foo( unsigned short, short, char );
/* ... Other code ... */
/* Assume this local variable is declared appropriately and is the only local var. */
struct fubar { char a[5]; unsigned short b; int c; short d[2]; } fb; /* Local variable fb */
/* ... Other code ... */
/ Write the code for just this function call saving the return value appropriately /
fb.c = foo(fb.b, fb.d[1], fb.a[3] );
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 0x
.align 2 s: .half 0xBA
.align 4 i1: .word 0xACDC i2: .word 0xACDC i3: .word 0xACDC x: .word 0
.section ".text" main: save %sp, -96, %sp set i2, %l set c, %l ldsb [%l1], %l sth %l1, [%l0] set fmt, %o ld [%l0], %o call printf _________________________________ nop set i3, %l set x, %l ldub [%l0+1], %l sth %l2, [%l1+2] ldsh [%l0+2], %l stb %l2, [%l1] mov %l1, %l set fmt, %o ld [%l0], %o call printf _________________________________ nop set i1, %l set s, %l lduh [%l1], %l sth %l1, [%l0+2] set fmt, %o ld [%l0], %o 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 L nop add %i2, %i0, %i mov 256, %o mov %i2, %o call .mul nop mov %o0, %i ba L nop
L1: add %l5, %l1, %l sub %i2, %i0, %i
L2: inc %i
/* Other code you cannot use */