CS 354, version A
Spring 2008
Name:___________________
ID:___________________
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 = _____ / 16
Q2 = _____ /   6
Q3 = _____ /   6
Q4 = _____ /   8
Q5 = _____ / 12
Q6 = _____ /   6
Total = _____ / 54




Question 1 (16 points total)
(12 points) List the six steps of the instruction fetch and execute cycle in their given (and correct) order.

  1. _____________________________
  2. _____________________________
  3. _____________________________
  4. _____________________________
  5. _____________________________
  6. _____________________________


(4 points) Which, if any, of these 6 steps may modify the Program Counter for a conditional control instruction?







Question 2 (6 points)
What 2 programs are used to translate high level language source code into machine code?

  1. _____________________________
  2. _____________________________






Question 3 (6 points)

#include <stdio.h>
#define MAX  4
int main(int argc, char *argv[]) {
   int array[MAX];
   int i;

   for (i = 0; i < MAX; i++) {
      array[i] = i;
   }

   printf("array element is %d\n", *(array + MAX));
   return(0);
}
In a single sentence, describe the programming error in this C program.







Question 4 (8 points, 4 points each)
Show your work in binary in doing the following 8-bit, two's complement integer operations. Give your answer in binary. For any integer arithmetic operation that causes overflow, write the word OVERFLOW next to the computed answer.


     11111101
   + 11101001
   -----------








     10110110
   - 11111100
   -----------



 





Question 5 (12 points)
Do 2 things:

  1. Using the diagram next to the code for the program variables, complete the diagram to show the values of each of the variables as the program runs. Use decimal values for the integers and arrows for the pointers.
  2. Write the output from an execution of this C program.

#include <stdio.h>

int main(int argc, char *argv[]) {
   int x;
   int y;
   int z;                     ------        ------
   int *px;                x |      |      |      | px
   int *py;                   ------        ------
   int *pz;
                              ------        ------
   x = 1;                  y |      |      |      | py
   y = 2;                     ------        ------
   z = 3;
   px = &x;                   ------        ------
   py = &y;                z |      |      |      | pz
   pz = &z;                   ------        ------

   *px = *pz;

   y = *pz + 10;

   *pz = *py + x;

   py = px;

   printf("x = %d, *px = %d\n", x, *px);
   printf("y = %d, *py = %d\n", y, *py);
   printf("z = %d, *pz = %d\n", z, *pz);

   return(0);
}



















Question 6 (6 points)
The 32-bit variable A initially contains the (hexadecimal) value 0xffffaaaa.
The 32-bit variable B initially contains the (hexadecimal) value 0xccccffff.

The following invented assembly language instructions are executed using these variables.

  xor  C, A, B
  rotl D, C, 4
These assembly language follow the following rules.
What are the (hexadecimal) values of variables C and D after execution of these 2 instructions?