






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, focusing on topics such as 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!







SubTotal ___________________ (100 points)
Extra Credit ___________________ (6 points)
Total ___________________
Convert 0xF939 (2’s complement, 16-bit word) to the following. (6 points)
binary ____________________________________
octal 0 ___________________________________
decimal ____________________________________
Convert -328 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 +477 to the following (assume 16-bit word). Express answers in hexadecimal. (3 points)
sign-magnitude 0x_______________________________________________
1’s complement 0x_______________________________________________
2’s complement 0x_______________________________________________
11010111 11000101 01111111 +10001001 +00111001 +
N Z V C N Z V C N Z V C
| | | | | | | | | | | | | | |
What is the value of %l0 after each statement is executed? Express your answers in hexadecimal.
set 0x9B9C4321, %l sra %l0, 13, %l
Value in %l0 is 0x_______________________________________ (2 points)
set 0x9B9C4321, %l sll %l0, 11, %l
Value in %l0 is 0x_______________________________________ (2 points)
set 0x9B9C4321, %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
Write the equivalent unoptimized SPARC assembly language instructions to perform the following C code fragment. All local variables must be allocated on the run time stack. (12 points)
C SPARC assembly
/* Function Prototype */
char foo( unsigned short, int, char );
/* ... Other code ... */
/* Local stack variables */
char a; unsigned short b[2]; char c; int d[2];
/* ... Other code ... */
/* Write the code for just this Put your SPARC Assembly code function call saving the in the box below. return value appropriately */
a = foo( b[1], d[0], c );
.global main .section ".data" fmt: .asciz "0x%X\n"! prints value as hex 0xXXXXXXXX
c: .byte 0xBB
.align 2 s: .half 0x
.align 4 i1: .word 0x i2: .word 0x i3: .word 0x 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 (6 points)
What gets printed at each printf() statement given the following C program?
#include <stdio.h>
int main() { char s[] = "absolute"; char *p = s;
printf( "%c\n", p++ ); ______ --(p+4); printf( "%c\n", *++p ); ______ p = p+1; *p = *(p-3) + 4; printf( "%c\n", p[0] ); ______ *(p+1) = p[1] + 2; printf( "%c\n", *++p ); ______ p++; printf( "%c\n", *p++ ); ______ p[0] = *(p+1); printf( "%s\n", s ); ______________________
return 0; }