






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 ___________________ (100 points)
Extra Credit ___________________ (5 points)
Total ___________________
1. Number Systems
Convert 0xFB7A (2โs complement, 16-bit word) to the following. (6 points)
binary ____________________________________
octal 0 ___________________________________
decimal ____________________________________
Convert -393 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 +506 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 +00111001 +
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 0xABCDEF19, %l sra %l0, 9, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0xABCDEF19, %l sll %l0, 13, %l
Value in %l0 is 0x _______________________________________ (2 points)
set 0xABCDEF19, %l set 0x????????, %l xor %l0, %l1, %l0! Value in %l0 is now OxFEEDCAFE
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 */
char foo( long, short, char );
/* ... Other code ... */
/* Assume this local variable is declared appropriately and is the only local var. */
struct fubar { char a[3]; short b; long c; short d; char e; short f[2]; } fb; /* Local variable fb */
/* ... Other code ... */
/ Write the code for just this function call saving the return value appropriately /
fb.e = foo( fb.c, fb.d, fb.a[1] );
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 0xBB
.align 2 s: .half 0x87B
.align 4 i1: .word 0xABCD i2: .word 0xABCD i3: .word 0xABCD 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+3] set fmt, %o ld [%l0], %o call printf _________________________________ nop set i3, %l set x, %l ldub [%l0+1], %l stb %l2, [%l1] ldsh [%l0], %l sth %l2, [%l1+2] mov %l1, %l set fmt, %o ld [%l0], %o1 _________________________________ call printf nop ret restore
Extra Credit (5 points) Write a function in SPARC Assembly that takes two unsigned ints and interleaves the lower two bytes into a full-length unsigned integer and returns that interleaved value. For example,
word1: 0x 00 00 CA 73 word2: 0x 00 00 D4 B
interleaves the lower two bytes to produce
result: 0x CA D4 73 B
You may use only the following assembly instructions: and , or , sll,set (along with save , ret , restore ). (You should be able to do this with 4 and , 3 or , 3 sll , and 1 set instructions.)
Here is the function prototype for this function:
unsigned int interleave_bytes( unsigned int word1, unsigned int word2 );