Computer Science 281
Final Exam
Name _________________
Tuesday, May 13
2:00
200 Pts.
I. Data representation (20 pts.) Consider the following code:
a: da.b '-13'
b: dc.w -13
c: ds.l 2
fmove.l #-13,fp0
fmove.d fp0,c
Write in hex the data that would be found in locations a, b, and c.
a:
b:
c:
II. (20 pts.) Write a complete procedure (subroutine) which will accept an integer passed by value on the stack and which will place a -1 in D0 if the number is prime, and a 0 in D0 otherwise. In this (and in the following questions calling for procedures), be sure to follow the usual conventions regarding the use of stack frames and register usage in subroutines.
III. Some data structure questions
a. (20
pts.) Given the following:
record
student_rec = record
student_number
: packed array [1..5] of char;
{i.e.,
PIC X(5)}
student_name
: packed array [1..10] of char;
exam_average
: integer; {assume longint}
end
Class
: array [1..100] of student_rec
Write
the code to implement
writeln(Class[15].student_name);
b. (20 pts.) Given
x : array [1..3,1..4] of integer {assume longint}
Write the code necessary to implement
writeln(x[i,j]);
Assume that i and j are found in D0 and D1 respectively.
IV. A rather long question (50 pts.)
Solutions
to an equation of the form ax+ bx + c = 0 can be found by the following algorithm:
1. Input
a, b, and c
2. If
a = b = 0, there is no solution
3. if
a = 0 and b <> 0 then x = -
4. if
a <> 0, then calculate d = b- 4ac, and consider the following three subcases
a. if
d = 0, then there is one solution, given by
x
= .
b. if
d > 0, there are two solutions, given by
x
= and x =
c. if
d < 0, there are no solutions
On this and the following page, write a complete
program which will accept a,b, and c as integers and which will solve the
equation given above and print the answer (as floating point). Do not include comments or user prompts
(limit input/output to numbers only), and assume that you have access to an
external sqrt function which accepts a double precision number on the system
stack and replaces that input on the stack with the square root.
Workspace for problem IV
V. (30 pts.) Given the following:
type
tree_rec = record
left,right
: pointer to tree_rec;
name
: packed array [1..10] of char;
end;
Write a complete recursive procedure (subroutine) which will accept the addresses of the roots of two of these trees as arguments (passed by value) and which will place a -1 in D0 if the two trees are equal, and a 0 otherwise. Two binary trees are equal in this case if the two name fields of the root nodes are equal and if the left and right subtrees are equal.
VI. Digitial circuitry
a. (15 pts.) What will the output of the following circuit with the given setting of the input switches (Out = on or off)? What logical function of the three inputs does the circuit compute? In your answer, refer to switch 1 as A, switch 2 as B, and switch 3 as C
b. (10 pts.) What sequence of 0's and 1's will the following circuit accept (i.e., will cause the light to go on)?
c. (15 pts.) Using only AND gates and inverters, construct a digitial circuit to compute the XOR of two inputs.