CDA3101 Assignment 2

advertisement
CDA3101 Assignment 2
Due 6/1
Submissions are due by the beginning of class on the specified due date. Handwritten
or typed solutions are acceptable. If you do write your solutions by hand, be sure to
write clearly. If the grader cannot read your answer, they cannot give you the points.
Late submissions will be accepted with a 10% penalty for each day they are late (up to
48 hours). You must show how you arrived at the answer or no credit will be given.
1. (25 pts) Translate the following MIPS assembly fragment below into C. Assume the
C-level integer i is held in register $t1, $s2 holds the C-level integer called result
and $s0 holds the base address of the integer array MemArray.
LOOP:
L1:
addi
sll
addu
lw
bne
addi
addi
slti
bne
$t1, $zero, 0
$t2, $t1, 2
$t2, $t2, $s0
$t2, 0($t2)
$t2, $zero, L1
$s2, $t1, 0
$t1, $t1, 1
$t2, $t1, 100
$t2, $zero, LOOP
2. (25 pts) Translate each of the following C statements below into MIPS assembly.
Assume that the variables f, g, and h are assigned to registers $s0, $s1, and $s2,
respectively. Assume that the base address of the arrays A and B are in registers $s6
and $s7, respectively. All $tx registers are available for use.
a. f = g – h + B[4];
b. f = g * A[B[3]];
Assignment 2 continues on the next page.
3. (20 pts) For each of the following actions, indicate the translation phase during which
the action takes place (preprocessing, compiling, assembling, linking, or loading).
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
Translating i = i + 1 to addi $t0, $t0, 1.
Including the contents of <stdio.h>.
Placing printf in the symbol table and call printf in the relocation table.
Allocating space for a.out in main memory.
Detecting the syntax error a * b =c;.
Creating a.out from main.o and frac.o.
Expansion of #define PI 3.14159 in the program text.
Detecting the semantic error a = b, where a in an int and b is a char array.
Translating addi $t0, $t0, 1 to 00100001000010000000000000000001.
Updating the symbol table entry for printf (patching external reference).
4. (15 pts) In class, we said that the logic equation for the result of an adder can be
expressed in the following way:
Sum = (a̅ ∙ b̅ ∙ CarryIn) + (a ∙ b̅ ∙ ̅̅̅̅̅̅̅̅̅̅
CarryIn) + (a̅ ∙ b ∙ ̅̅̅̅̅̅̅̅̅̅
CarryIn) + (a ∙ b ∙ CarryIn)
Using only AND, OR, and NOT gates, design the hardware that will implement Sum.
You may use the more convenient bubble-notation instead of explicitly drawing NOT
gates. Try to draw as clearly as possible for the grader.
5. (15 pts) Using the truth table below, write a logic equation for D in terms of the input
values A, B, and C. Your logic equation must be in canonical form as a sum-ofproducts.
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
D
1
0
0
1
0
1
1
0
Download