main.c
, logic.h
, and logic.c
.
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 worry about 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 PA4, type the following command:
$ makeTo run the compiled program, type the following command:
$ ./PA4Part 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 that 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 |
Save Target As..
for each of the files:
cd
to the directory created in step 1. make
to build the executable. You
should see the following output:
Compiling each C source file separately ...
gcc -g -std=c99 -Wall -O0 -c main.c
Compiling each C source file separately ...
gcc -g -std=c99 -Wall -O0 -c logic.c
Linking all object modules ...
gcc -g -std=c99 -Wall -O0 main.o logic.o -o PA4
In the terminal type ./PA4
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.
Also, answer the questions in PA4.QandA. 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.
You will be submitting a single file PA4.tar
using the Checkin tab./b>.
The tar ball should include the following files: logic.c, logic.h, and main.c
.
Bring the PA4.QandA
file to class on March 4 for a group discussion. The
file PA4.tar
is made by the Makefile, just type make package
.
Check your source files to make sure you have put comments in all of
the source files.