Computer Science 281
Hour Exam #1
Name
____________________________
Friday, Feb. 15
90 pts. (will be adjusted to 100 in the gradebook)
1. (10 pts.) Briefly describe the instruction-fetch-execute cycle and explain how pipelining helps increase throughput (i.e., helps increase the number of instructions that can be processed in a given period of time).
2. (10 pts.) We begin assembly language subroutines with the .global directive as, for example, .global calc. What is the role of this, and how does the link editor use it?
3. (10 pts.) Suppose that we have a stack machine with instructions to push a value onto the stack (e.g. PUSH X, PUSH 1), an instruction to pop a number off the stack into a memory location (POP Y), and stack instructions ADD, SUB, MUL, DIV which operate on the top two elements of the stack and push the result onto the stack (recall that SUB subtracts the number at the top of the stack from the one underneath it). Given that and the first and last instructions, complete the following code segment in this machine to perform the calculation
Y = (X-1)*(X+1)
PUSH X
POP Y
4. (20 pts.) Suppose we have a main program in C that looks like
#include <stdio.h>
int main() {
int x,y,z;
printf("Please
enter a value for x ->");
scanf("%d",&x);
printf("Please
enter a value for y ->");
scanf("%d",
&y);
z = avg(x,y);
printf("The result
is %d\n", z);
}
Write an assembly language routine which implements the avg function. The function should take two integer arguments (x and y) as input, calculate and return (x + y) / 2. Please recall that the .div subroutine calculates %o0 / %o1 and returns the result in %o0. Include enough comments so that I can see what is going on.
5. (15 pts.) Implement in assembly language the statement
if (%g0 < %g2)
then move %g0into %o0
else move %g2 into %o0
6. (15 pts.) Implement the following code in assembly language:
sum = 0;
for (i = 0; i < 10; ++i)
sum = sum + i;
use %l0 (local 0) for sum and %l1 (local 1) for i.
7. (5 pts.) Write the M4 statements necessary to remove magic numbers
from the following statement:
for (i = 0; i < 10; ++i)
sum = sum + i
8. (5 pts.) Briefly say who one of the following two people are:
Grace Hopper
Ada Lovelace