Assignment 8, due Mar 28Solutions
Part of
the homework for 22C:60 (CS:2630), Spring 2014

On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper at the start of class on the day indicated (usually Friday). Exceptions will be made only by advance arrangement (excepting "acts of God"). Late work must be turned in to the TA's mailbox (ask the CS receptionist in 14 MLH for help). Never push homework under someone's door!
A problem: Make a table showing all possible combinations of f_{1}, f_{2}, f_{3}, and c_{0} (the carry in to the least significant bit). For each row in this table (that is, for each combination of the inputs) document the function performed by this bank of logic circuits. (for example, one row might compute A+B+1, while some other row might compute A&B, and yet another row might perform some useless function. (1.0 points)
f_{1} f_{2} f_{3} c_{0} Function 0 0 0 0 — 0 0 0 1 — 0 0 1 0 a & b 0 0 1 1 — 0 1 0 0 — 0 1 0 1 — 0 1 1 0 — 0 1 1 1 — 1 0 0 0 a ⊕ b 1 0 0 1 — 1 0 1 0 a  b 1 0 1 1 — 1 1 0 0 a + b 1 1 0 1 a + b + 1 1 1 1 0 — 1 1 1 1 —
Loop unrolling involves repeating the body of the loop in order to reduce the number of iterations.
Background: Compare the code for faster binary multiplication on the Hawk (about 1/5 of the way into Chapter 9) with the code for fast signed multiplication on the Hawk. The most obvious difference between these two is that the signed version has a special case for the sign bit of the multiplier before the main loop of the multiplication. There are some other important differences.
A Problem They shift different things. Very briefly state what each routine shifts and which way it shifts it. (0.4 points)
The routine for faster binary multiplication shifts the multiplier right and the multiplicand left.
The routine for fast signed multiplication shifts both the multiplier and the product left.
ADDSL R3,R3,2 ; R3 times 5 \ ADDSL R3,R3,2 ; R3 times 5 > since 75 = 3 × 5 × 5 ADDSL R3,R3,1 ; R3 times 3 /
SRU R3,1 SRU R4,1 ADJUST R1,CMSB
The above code is from section 11.2 of the Hawk manual.
A Problem: There is a much faster way to do this using 2 12bit rightshifts, a 20bit left shift and a small number of auxiliary instructions. Give the best code you can for this. The very best code is surprisingly compact. (0.8 points)
MOVESL R5,R4,10 SL R5,10 SRU R3,12 SRU R4,12 OR R4,R5