CS 354, version A
Spring 2006
Name:___________________
ID:___________________
Login:_____________________
Exam 1

No electronic devices may be used while taking this exam. Examples of devices not allowed are calculators, pagers, cell phones, wrist calculators/computers, laptop computers, pocket computers. Each student is allowed one 8.5 by 11 inch sheet of paper with handwritten notes. The notes may be on both sides of the paper.

Show all work, and do any/all calculations on the exam. Extra scratch paper may not be used.

Exam Score
Q1 = _____ /   6
Q2 = _____ /   6
Q3 = _____ / 10
Q4 = _____ /   8
Q5 = _____ /   8
Q6 = _____ /   8
Q7 = _____ / 15
Total = _____ / 61



Question 1 (6 points total)
PART A (4 points) The six steps of the instruction fetch and execute cycle are given. Number the steps (starting with 1) to show their proper and given order.

_____ store the result

_____ decode

_____ update PC

_____ do the instruction's operation

_____ get operands

_____ instruction fetch

PART B (2 points) Which one of these steps may be placed at a different position within the ordering, if the efficiency of modern hardware implementations were not considered?

Question 2 (6 points)
A Unix command line appears as

% a.out min 10 error -1
Diagram argc and argv as they are given to a C program.















Question 3 (10 points)
Write the output from this C program to the right of the source code.


#include <stdio.h>
#define MAX  500

/* function addones */
void  addones(int x, int *y, int *z){
    x++;
    (*y)++;
    (*z)++;
}


main()
{
   int array[MAX];
   int *arrayp;
   int a = 100;
   int b = 200;
   int c = 300;
   int *ap;
   int *bp;
   int *cp;
   int i;      /* loop induction variable */

   arrayp = array;
   for (i=0; i<MAX; i++) {
      *arrayp = c - i;
      arrayp++;
   }
   arrayp = array;
   printf("%d, %d, %d\n", array[100], *(array + 12), *(arrayp + 12));

   ap = &a;
   bp = &b;
   cp = &c;

   addones(a, &b, cp);
   printf("%d, %d, %d\n", a, b, c);

   return(0);

}

Question 4 (8 points)
Give a base 4 representation for the value 312.26. Show any repeating digits by placing a bar over those digits that repeat.













Question 5 (8 points)
Part A What decimal value is represented by the 8-bit, two's complement representation 10011111?








Part B What is the 8-bit, two's complement representation for the decimal value 36?









Question 6 (8 points)
Give the IEEE single precision floating point representation (in hexadecimal) for the decimal value -12.75.































Question 7 (15 points, 3 points each part)
Assume that X is a 32-bit variable and has the value 0xffffff4c. Y is a 32-bit variable and has the value 0x000000a3. Show your work (where possible) in doing the following operations. Give your answer in binary and in hexadecimal for Parts A-D. For any integer arithmetic operation that causes overflow, write the word "OVERFLOW" next to the computed answer.
Part A
unsigned addition: X + Y





Part B
two's complement subtraction: X - Y







Part C
bitwise logical operation: X nand Y







Part D
arithmetic right shift of X by 3 places







Part E
printing the rightmost byte of X, what character gets printed?