Assignment 8, due Oct 24
Part of
the homework for CS:2630 (22C:60), Fall 2014
|
On every assignment, write your name legibly as it appears on your University ID card! Homework is due on paper Homework is due on paper at the start of class on the day indicated (usually Friday). 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: Give the logic diagram (in graphical notation) for the logic that produces a true output if the BGT instruciton is supposed to branch, and a false output if not. (0.5 points)
leftshift( int a, int c) { // iterative shifter while (c > 0) { a = a << 1; c = c - 1; } return a; }
Consider the following alternative:
leftshift( int a, int c) { // software barrel shifter if (c & 1) a = a << 1; if (c & 2) a = a << 2; if (c & 4) a = a << 4; if (c & 8) a = a << 8; if (c & 16) a = a << 16; return a; }
The iterative shifter and the barrel shifter produce the same result for all values of c from 1 to 31.
a) What is the result of the iterative shifter for larger values of c? (0.2 points)
b) What is the result of the barrel shifter for larger values of c? (0.2 points)
c) Code the barrel shifter as a SMAL Hawk assembly language subroutine. Take advantage of the BITTST instruction for testing individual bits of a register (see Section 6.4 of the Hawk manual). (0.6 points)
a) × 120. (0.3 points)
b) × 192. (0.3 points)
c) × 500. (0.3 points)
Hint: Two 4-bit right-shift instructions get all but 4 bits of the result correct. The problem is to rescue those 4 bits. This can be done with some left shifting and an add. Keep in mind that the maximum shift count that the hawk permits is 16, but some of the shifting you need to do requires more. This will take multiple instructions. and an add