





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






**1. Number Systems ___________________ (15 points)
SubTotal ___________________ (82 points)
Extra Credit ___________________ (4 points)
Total ___________________
1. Number Systems
Convert DADA 16 (2’s complement, 16-bit word) to the following. (6 points)
decimal ____________________________________
octal 0 ___________________________________
binary ____________________________________
Convert +431 10 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points)
sign-magnitude 0x _______________________________________________
1’s complement 0x _______________________________________________
2’s complement 0x _______________________________________________
Convert -274 10 to the following (assume 16-bit word). Express answers in hexadecimal. (6 points)
sign-magnitude 0x _______________________________________________
1’s complement 0x _______________________________________________
2’s complement 0x _______________________________________________
4. Bit Operations / C Runtime Environment
What is the value of %l0 after each statement is executed? Express your answers in hexadecimal.
set 0xFEEDFACE, %l sll %l0, 11, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0xFEEDFACE, %l sra %l0, 9, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0xFEEDFACE, %l set 0xCDCAB072, %l xor %l0, %l1, %l
Value in %l0 is 0x _______________________________________ (2 points)
Fill in the names of the 5 areas of the C Runtime Environment as layed out by most Unix operating systems. 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 frag- ment. You can assume just this one local variable. (10 points)
C SPARC assembly
/* Function Prototype */
int foo( short, char );
/* ... Other code ... */
/* Assume this local variable is declared appropriately and is the only local var. */
struct fubar { int a; char b; int c; short d; long e; } fb; /* Local variable fb */
/* ... Other code ... */
*Write the code for just this function call saving the return value appropriately /
fb.c = foo( fb.d, fb.b );
Extra Credit (4 points)
Optimize your solution to the checkRange() problem #3 earlier in this exam. The restrictions now are:
The only instructions you can use are: save , cmp , ble , bge , ba , restore , mov , ret The following instructions can be used only once: save , ble , bge , ba , restore , ret The other instructions can be used more than once: cmp , mov The only registers you can use are: %i0 , %i1 , %i Note: there can be no nops It is up to you whether you use annulled branches or not (it really doesn’t matter if you do or not).
/* int checkRange( long value, long minRange, long maxRange ); / / Return value of 0 means No, theValue was not in the range; 1 otherwise. */