CS 202 - Homework 5 - 10/8/07

This homework has three parts and covers both circuits and assembly programming.

Part 1: LogicWorks warmup exercise

Due: this Wednesday, 10/10/07, in class

This is a short exercise to get you acquainted with LogicWorks, the digital simulator software to be used in this course. You may work in groups of two for this part only, or by yourself if you prefer.

LogicWorks 4 runs under Windows, and is installed MBH 632 (you'll have to reboot the machines into Windows). Here's what to do:

  1. Do the "5-minute tutorial" in the manual (chapter 4, pp. 47-63). Manuals are available in lab (please leave them there!). There is nothing to be handed in for this part.

  2. Implement a 3-bit binary to unary converter, analogous to the 2-bit converter discussed in class. Your circuit should have 3 inputs (A2, A1, A0) and 7 outputs (Y1, ..., Y7). Try to minimize the number of gates - it is possible to have a total number of inputs on all gates that is less than 20. Test your circuit by attaching a hex keyboard to the three inputs, and seven binary probes to the outputs. (You can find basic gates in the "Simulation Gates.clf" library, and binary probes and hex keyboards in the "Simulation IO.clf" library. Alternately, select "ALL LIBRARIES" and use the "Filter" text box to find specific components.)

    When you are done, add your name(s) to the circuit, print it out, and hand in the printout in class on Wednesday (only one submission per group).


Part 2: 4-Bit Adder/Subtracter

Due: Wednesday, 10/17/07, in class (or by 2pm the latest)

Implement a 4-bit adder/subtracter as discussed in class. Your circuit should have 9 inputs (A0..3, B0..3, SUB) and 5 outputs (Y0..3, CARRY). You may only use parts from the "Simulation Gates.clf" library for your circuit (and parts from the "Simulation IO.clf" library to test it).

Once your circuit works, package it nicely into a subcircuit (see the LogicWorks manual, Chapter 6 / Using Subcircuits, pp. 149-158, in particular page 157). You will need to connect "Port In" and "Port Out" devices from the "Connect.clf" library to the inputs and outputs of your circuit, and you should remove all testing devices, such as switches and keyboards. Then, you will need to start the device editor, and draw a symbol for your circuit. Try to use the right pin spacing (2 ticks in the device editor) so that your subcircuit can easily be connected to two hex keyboards and one hex display as shown below.

Hand in a printout of the implementation of your circuit, as well as a printout of your testing configuration using the "packaged" subcircuit (which should look like the picture above). Add your name to both designs using the text tool before you print it! In case you have defined additional subcircuits, hand in printouts of those as well.


Part 3: Selection Sort in Pentium Assembly

Due: Wednesday, 10/17/07, in class (or by 2pm the latest)

Just so you don't immediately forget your assembly programming skills, I figured I'd let you have some fun writing selection sort in assembly. Here is a C function you should use as a model for your assembly function:
/* sort array elements a[0]..a[n-1] using selection sort */
void selSort(int a[], int n)
{
  int i, j, tmp;
  
  /* i = number of unsorted elements */
  for (i=n-1; i>0; i--) {
    
    /* find maximum among unsorted elements */
    int maxpos = 0;
    for (j=0; j<=i; j++) {
      if (a[j] > a[maxpos])
	maxpos = j;
    }

    /* swap max and last unsorted element */
    tmp = a[maxpos];
    a[maxpos] = a[i];
    a[i] = tmp;
  }
}
A driver to test your program is provided in ~schar/cs202/hw5/. Also, take a look at our last assembly program from class, arrmax.s - you may even be able to reuse part of this code. Please document your assembly code well. In particular, please include a comment explaining the register use. You may want to use all six registers - if you do, don't forget to save %ebx, %esi, and %edi on the stack first.


On you submission for parts 2 and 3, please write down how much time it took you, as well as the names of any students with whom you collaborated. You cannot work as a group here - every student has to create and submit their own implementation. As usual, however, you are encouraged to go to the lab together and help each other with the particulars of using LogicWorks and assembly.

Please also submit your assembly program electronically by typing ~schar/bin/submit202 in the directory containing your assembly file.