| 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.
(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?
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:
#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.
xor is a bitwise exclusive or instruction.
rotl is a rotate left instruction,
and the third (last) operand specifies the number of bits by which to rotate.
C and
D after execution of these 2 instructions?