CS30 Midterm Exam Fall 2007 - Prof. Richard Ord, Exams of Computer Science

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

2010/2011

Uploaded on 06/08/2011

koofers-user-mex
koofers-user-mex 🇺🇸

10 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Name _________________________
Student ID __________________ Signature_______________________
cs30x_______
CSE 30
Fall 2007
Midterm Exam
1. Number Systems ___________________ (15 points)
2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
3. Branching ___________________ (20 points)
4. Bit Operations / C Runtime Environment ___________________ (17 points)
5. Parameter Passing and Return Values (Stack Variables) ___________________ (12 points)
6. Local Variables, The Stack and Return Values ___________________ (15 points)
7. Load/Store/Memory ___________________ (9 points)
SubTotal ___________________ (100 points)
Extra Credit ___________________ (6 points)
Total ___________________
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download CS30 Midterm Exam Fall 2007 - Prof. Richard Ord and more Exams Computer Science in PDF only on Docsity!

Name _________________________

Student ID __________________ Signature_______________________

cs30x_______

CSE 30

Fall 2007

Midterm Exam

  1. Number Systems ___________________ (15 points)
  2. Binary Addition/Condition Code Bits/Overflow Detection ___________________ (12 points)
  3. Branching ___________________ (20 points)
  4. Bit Operations / C Runtime Environment ___________________ (17 points)
  5. Parameter Passing and Return Values (Stack Variables) ___________________ (12 points)
  6. Local Variables, The Stack and Return Values ___________________ (15 points)
  7. Load/Store/Memory ___________________ (9 points)

SubTotal ___________________ (100 points)

Extra Credit ___________________ (6 points)

Total ___________________

  1. Number Systems

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_______________________________________________

  1. 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)

11010111 11000101 01111111 +10001001 +00111001 +


N Z V C N Z V C N Z V C


| | | | | | | | | | | | | | |


  1. Bit Operations / C Runtime Environment

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

  1. Parameter Passing and Return Values (Local Stack Variables)

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 );

  1. 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 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; }

Scratch Paper