CS1101C Lab 3 (Odd Week)

Gate-Level (SSI) Design

The deadline for this lab question is Friday 19 October 2007, 23:59:59 hours.

The name of your C program file must be called ssi.c, files with any other name will not be marked.

Preliminary

For this lab, we shall use C functions to represent logic gates and small-scale integration (SSI) chips. By composing logic gates and chips together, we would eventually design and realize a full adder logical circuit. This lab is separated into parts, so please complete one part before you embark on the other one. In other words, working from the smallest module (or function), you should test and ensure that each function works correctly.

1. AND/OR/NOT logic gates

We shall first come up with the three most basic logic gates for AND, OR, NOT. The function prototypes of the three functions is listed below:
int not(int);
int and(int, int);
int or (int, int);
The truth table and logic gate diagrams are given below:

Input Output
A NOT
0 1
1 0
Input Output
A B AND
0 0 0
0 1 0
1 0 0
1 1 1
Input Output
A B OR
0 0 0
0 1 1
1 0 1
1 1 1

Throughout this lab, we shall assume that inputs and outputs can only be of values 0 or 1. Your task for this part is simply to define the functions. Test your functions and ensure that they work.

2. XOR logic gate

The AND/OR/NOT logic gates are the only logic gates you'll ever need to implement any boolean function. We shall implement the XOR logic now. The truth table and logic diagram for XOR is given below. Your task now is to write a function of prototype

int xor (int,int);
that realizes the XOR logic. You'll will need to apply your powers of logical inference here. Make use of the functions that you defined in Section 1 above.

Input Output
A B XOR
0 0 0
0 1 1
1 0 1
1 1 0

Test and ensure that your function works accordingly before proceeding on.

3. Half Adder

A half adder is a single bit adder that has two inputs A and B, and two outputs S (sum) and C (carry). The logic circuit design of a half adder is given below.

Your task is to write a function with the following prototype:

void halfAdder(int a, int b, int *s, int *c);

Make use of the functions you have defined in Sections 1 and 2 above.

Use the following truth table to verify the correctness of your function implementation.

Input Output
A B C S
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0

4. Full Adder

The final SSI design is to realize a full adder using two half adders and one OR logic gate. The circuit design diagram is given below. Try to work out which are the components that make up the two half adders. You should not use any other logic gate or chips.

Define your function with the following prototype:

void fullAdder(int a, int b, int cin, int *s, int *cout);

Make use of the functions you have defined in Sections 1 / 2 / 3 above.

5. Test The Circuit

Write a main function that tests the output of your full adder designed above with all possible combinations of inputs. Assuming that the executable is ssi, a sample run of the program is shown below.

$ gcc -Wall ssi.c -o ssi

$ ./ssi

A B Cin   S Cout
----------------
0 0 0 --> 0 0
1 0 0 --> 1 0
0 1 0 --> 1 0
1 1 0 --> 0 1
0 0 1 --> 1 0
1 0 1 --> 0 1
0 1 1 --> 0 1
1 1 1 --> 1 1

Rather than enumerating the eight possible configurations, try to perform the enumeration using loops.

Note and Ponder

  1. If your program does not work as you expect (logical errors), use extra printf statements to print out all the values of your variables to aid in your debugging.

  2. Most importantly, have lots of fun programming!


This document, index.html, has been accessed 18 times since 25-Jun-24 11:57:13 +08. This is the 1st time it has been accessed today.

A total of 11 different hosts have accessed this document in the last 445 days; your host, 216.73.216.39, has accessed it 1 times.

If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.