My Project
CS270 Spring 2015
Programming Assignment P5: CS 270 Computer Organization

Programming Assignment P5 - Simulating Digital Logic


Programming due Sunday, Oct. 4 at 10:00pm, late submission until 11:59pm.


This assignment has three objectives:
  1. To learn how to simulate digital logic with C functions,
  2. to learn how to write unit tests in C using asserts,
  3. and to increase your understanding of circuits that are fundamental to computer hardware.

About the Assignment

For this assignment you will write a C program to simulate gates, latches, decoders, multiplexers, and an adder. You need to submit a tar archive with the code files: main.c, logic.h, and logic.c. The Makefile will have a target to make the archive by typing:
    $ make package
The logic.h and logic.c files already contain declarations, implementations, and the main program contains a unit test for each of the following functions:
    // Gates
    BIT or_gate(BIT A, BIT B);
    BIT not_gate(BIT A);

    // Sequential Circuits
    BIT rs_latch(BIT S, BIT R);
The header file also defines a BIT as an enumerated value. Add the functions shown below to the logic.c file, and corresponding tests to the main.c program. Note that O1 and O2 inputs to the adder function are 4-bits and unsigned, so you only need to deal with input values between 0 and 15.
    // Gates
    BIT and_gate(BIT A, BIT B);
    BIT xor_gate(BIT A, BIT B);

    // Sequential Circuits
    BIT d_latch(BIT D, BIT WE);

    // Combinational Circuits
    int adder(int O1, int O2,  BIT carryIn, BIT *carryOut);
    BIT multiplexer(BIT A, BIT B, BIT C, BIT D, BIT S1, BIT S0);
    void decoder(BIT A, BIT B, BIT *O0, BIT *O1, BIT *O2, BIT *O3);
To compile all files into a program called P5, type the following command:
    $ make
To run the compiled program, type the following command:
    $ ./P5
Part of this assignment is to make sure that each test is exhaustive for the gate or circuit being tested, i.e. all combinations of inputs should be tested, except for the multiplexer and the adder circuits, where you only need to test the cases shown. NOTE: you will need to determine what the correct output should be in each case and encode that in your unit test case.

MULTIPLEXER

A B C D S1 S0 Output
0 0 0 0 0 0
1 1 1 1 1 1
1 0 1 0 1 0
0 1 0 1 0 1

ADDER

O1 O2 Carryin Output Sum Output Carryout
0101 0101 0
0101 0101 1
0001 0111 1
0111 0111 0
1101 1101 1

Getting Started

Copy the following five files into the P5 working directory. It is easiest to right click on the link and do a Save Target As.. for each of the files: Open a terminal and cd to the directory created in step 1.
In the terminal, type make to build the executable. You should see the following output:
    Compiling each C source file separately ...
    c99 -g -Wall -O0 -c main.c

    Compiling each C source file separately ...
    c99 -g -Wall -O0 -c logic.c

    Linking all object modules ...
    c99 -g -Wall -O0 main.o logic.o  -o P5 
In the terminal type ./P5 to see that the program currently runs. The output should be as follows:
    ===== Testing not_gate =====
    ===== Testing or_gate =====
    ===== Testing rs_latch =====
As long as none of the asserts in main.c do not cause the program to halt, the implementations are correct.

You have a functioning program. There are some example unit tests in main.c and some example implementations in logic.c. You need to write comments in all of the source files, implement the rest of the functions specified in logic.h, write unit tests for all of the functions in main.c. Copy the methodology of asserts from the existing code in main for your test cases. Keep in mind that the unit test cases need to be exhaustive for all of the functions except for the multiplexer and the adder, as described above.


Submission instructions

You will be submitting a single file P5.tar using the Checkin tab. The tar ball should include the following files: logic.c, logic.h, and main.c. The file P5.tar is made by the Makefile, using the command make package. Check your source files to make sure you have put comments in all of the source files.


Reminders


Grading Criteria

To grade the assignment, we will verify that your logic functions work correctly (60 points), and that your test cases are comprehensive (40 points). NOTE: Minimal preliminary testing is setup for P5, which should be just enough to get you on the right track, since much of the assignment is for you to test your own code!
© 2015 CS270 Colorado State University. All Rights Reserved.