EECS 373 Winter 2005 Homework 1 (with solutions)

Due Tuesday February 15 by 4:30 pm. You may turn in a paper copy in class on February 15 or you may e-mail an electronic version to the lecture instructor (don@umich.edu). If you submit electronically, files should be in open, non-proprietary formats. Plain text, PDF, HTML, images in JPEG, PNG or TIFF, or OpenOffice/StarOffice .sxi files are all good formats. Microsoft Word files will be grudgingly accepted (as long as OpenOffice doesn't have trouble reading them). If you send me a logic diagram in some proprietary CAD format, I almost certainly won't be able to read it. Thus it is strongly recommended that diagrams be either turned in on paper or sent as PDF, JPEG, or PNG images. If you turn in work on paper, please be sure to put your uniqname on all sheets.

Problem 1 (address decoding)

A three hour tour took a bad turn and left you stranded on a desert island. Fortunately you have with you a digital emergency radio transceiver that you built as your EECS 373 final project. The project was all done and debugged, but when you turn it on, the Xilinx chip on the I/O board vaporizes in a foul smelling puff of smoke. Fortunately for you, all you were using this chip for was the address decoding. You happen to have a small breadboard with room for two integrated circuits, and you have one of each of the following logic circuits with you:

You will be rescued if you can build an address decoder with the following properties:

Draw a suitable decoder circuit.

Solution (not unique; several solutions are possible):

0x02a00000 is as follows:

A[6] = 1
A[7] = 0
A[8] = 1
A[9] = 0
A[10] = 1
A[11] = 0
A[12] = 0
A[13] = 0
A[14] = 0
A[15] = 0
A[16] = 0
A[17] = 0
A[18] = 0
A[19] = 0
A[20] = 0
A[21] = 0
A[22] = 0
A[23] = 0
A[24] = 0
A[25] = 0
A[26] = 0
A[27] = 0
A[28] = 0
A[29] = 0

Use a triple 3-input NOR gate and a single 8-input NAND gate.
Connect all three NOR gate outputs to NAND gate inputs.
Connect A[6], A[8], A[10] to NAND gate inputs.
Connect A[7], A[9], and A[11:17] to NOR gate inputs.
The two extra unused NAND gate inputs can be tied high or connected to other NAND gate inputs.
The output of the NAND gate is the decoder output.


Problem 2 (address decoding, optimized)

Continuing the same scenario as problem 1...

You successfully contact a rescue ship with your radio. You learn that there are several other stranded logic designers on other islands. You also learn that the rescue ship captain has an intense fear of all shadows, including shadow locations from partial address decoding. You are informed that rescues will be made in order of those whose address decoders produce the fewest number of shadow locations.

Subject to the same constraints as in the previous problem, design a suitable decoder (your answer may or may not be the same as in the previous problem) optimized to minimize the number of shadow locations.

Draw the circuit for your optimized design.

Solution: the solution shown for problem 1 above is acceptable.


Problem 3 (shadow location counting)

What is the total number of word aligned memory addresses that your optimized design for Problem 2 will respond to?

Solution: A[18:29] are all not decoded, so they are essentially "don't care" values.
There are 12 such bits, so the decoder will respond to 2**12 = 4096 word addresses.


Problem 4 (assembly language programming, EABI)

Write an EABI compliant PPC assembly language function that computes the signum function of a number. This function is defined a -1 for a negative input, +1 for a positive input, and 0 for a zero input. Here is one possible implementation in C:
int signum(int x) {
  if (x < 0) return -1;
  if (x == 0) return 0;
  if (x > 0) return 1;
}
You do not have to implement your solution in the same way as the C program; if you can find a way to do it without conditional branches feel free to do so. For full credit, you must fully follow the EABI specification. (One extra credit point will be given for particularly elegant or efficient solutions)

Solution (not unique):
signum:srawir4,r3,31# x >> 31
negr5,r3# -x
srwir5,r5,31# t = (unsigned) -x >> 31
orr3,r4,r5# sign(x) = (x >> 31) | t
blr

The srawi does an algebraic (sign extending) right shift of x by 31 bits, so only the sign bit is retained (but it is sign extended to fill all 32 bits). The result is r4 = -1 if x is negative, r4 = 0 if x is zero or positive.

The neg and srwi does a logical (unsigned) right shift of x by 31 bits, and it is not sign extended. The result is r5 = 1 if (-x) is negative, r4 = 0 if (-x) is zero or positive. In other words, the result is r5 = 1 if x is positive, r4 = 0 if x is zero or negative.

The last step or's the results together to produce the final result. The table below shows the final register values for positive, zero, and negative input.

input r4 r5 r3
positive011
zero000
negative-10-1


Problem 5

There is no problem 5.


Problem 6 (assembly language programming, EABI)

You are to write an EABI compliant PPC assembly language function to implement the blurfl function, which is defined as follows:

blurf(x,y) = smurfl(11,y) - smurfl(x,-7)

Assume an ABI compliant implementation of smurfl(u,v) exists that you may call as needed. Write only the code for blurfl; do not write any code for smurfl or for the caller of blurfl.

Solution: There is more than one way to do this, but in any case two things must be preserved: the parameter x must be preserved across the first call of smurfl to use it in the second call to smurfl, and the result of the first call to smurfl is an intermediate result that must be preserved across the second call. These aren't needed at the exactly same time, so nonvolatile register r31 can be shared to hold both of these. Thus, r31 must be saved on the stack on entry to blurfl and restored on exit.

blurfl:mfsprr0,LR
stwr0,4(r1)
stwur1,-16(r1)
stwr31,12(r1)
orir31,r3,0
lir3,11
blsmurfl
orir4,r3,0
orir3,r31,0
orir31,r4,0
lir4,-7
blsmurfl
subr3,r31,r3
lwzr31,12(r1)
addir1,r1,16
lwzr0,4(r1)
mtsprLR,r0
blr


Problem 7:

The following bit string is to be transmitted through a USB connection:

010110111011110111110111111011111110111111110001000001000000010000000001

Show the resulting bit string after both bit stuffing and NZRI encoding have been applied to this bit string. When determining the NZRI encoding, assume that the immediately preceding bit sent was "1". You must show your work to be eligible for partial credit.

Solution: after bit stuffing:

010110111011110111110111111001111110101111110110001000001000000010000000001

After NZRI encoding:

001110000111110000001l11111011111110011111110001011010100101010110101010100