The name of your C program file must be called ssi.c, files with any other name will not be marked.
int not(int); int and(int, int); int or (int, int);The truth table and logic gate diagrams are given below:
![]()
|
![]()
|
![]()
|
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.
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.
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 |
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.
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.
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.