This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:jr018429:portfolio:my4-bit_cpu.html [2013/11/11 03:23] – jr018429 | user:jr018429:portfolio:my4-bit_cpu.html [2013/11/11 04:16] (current) – jr018429 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP centeralign round graybg box 96%> | ||
+ | <WRAP muchbigger> | ||
+ | <WRAP bigger> | ||
+ | <WRAP bigger> | ||
+ | </ | ||
+ | ======Objectives====== | ||
+ | To create a software simulator for the 4-Bit Computer project described at the www.waitingforfriday.com Website (see references section at the bottom of the page). | ||
+ | ======Prerequisites====== | ||
+ | *C/C++ Programming Experience | ||
+ | *Knowledge of Digital Logic | ||
+ | *Knowledge of basic CPU Architecture | ||
+ | ======Background====== | ||
+ | The 4-bit computer project at www.waitingforfriday.com was the inspiration for this project.\\ | ||
+ | < | ||
+ | The waitingforfridays 4-bit computer is built from switches, transistors and components to bias them for digital operation rather than from logic gates. It isn't really a 4-bit CPU but rather a 4-bit adder with carry out. An adder is a component of a CPU. Furthermore, | ||
+ | This project contains not one but two simulators. The first, fourBitComputer, | ||
+ | To use either simulator, in Windows open the command or console window. Using the command line, navigate to the location of the simulators. On the command line, enter either either of the aforementioned simulators with the -h switch. Help information regarding how to enter data into the simulator is returned:\\ | ||
+ | **Execution of fourBitComputer.exe**\\ | ||
+ | <cli> | ||
+ | C: | ||
+ | Usage: fourBitComputer [1st 4-bit binary field] [2nd 4-bit binary field] | ||
+ | 1st binary field-adden 1 | ||
+ | 2nd binary field-adden 2 | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of fourBitComputer2.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | Usage: fourBitComputer [1-bit binary field] [4-bit binary field] [4-bit binary f | ||
+ | ield] | ||
+ | 1st binary field-operation | ||
+ | 2nd binary field-adden 1/minuend | ||
+ | 3rd binary field-adden 2/ | ||
+ | |||
+ | Commands: | ||
+ | 0 = add | ||
+ | 1 = subtract | ||
+ | |||
+ | Returns: | ||
+ | carry/not borrow | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | Both simulators have an extra result bit. During operation of the fourBitComputer simulator, the extra result bit is set only if the result of an addition operation is greater than 111 binary or 15 decimal. During the operation of the fourBitComputer2 simulator, however, the extra result bit is set depending on the result of either an addition or a subtraction operation, and therefore functions as a carry/not borrow bit. Note that this is how a carry/not borrow status register flag operates. Therefore, not only can these simulators add and subtract, but they also have a status bit whose state is dependent upon operation and the values used in the operation. | ||
+ | ======Code====== | ||
+ | **makeLogicandCPU.bat**\\ | ||
+ | < | ||
+ | REM makeLogicandCPU.bat | ||
+ | REM John T. Rine | ||
+ | REM 11-10-2013 | ||
+ | del *.exe | ||
+ | del *.o | ||
+ | del *.a | ||
+ | g++ -c notGate.cc -o notGate.o | ||
+ | g++ -c orGate.cc -o orGate.o | ||
+ | g++ -c andGate.cc -o andGate.o | ||
+ | g++ -c norGate.cc -o norGate.o | ||
+ | g++ -c norFF.cc -o norFF.o | ||
+ | g++ -c nandGate.cc -o nandGate.o | ||
+ | g++ -c xorGate.cc -o xorGate.o | ||
+ | g++ -c nandFF.cc -o nandFF.o | ||
+ | g++ -c xnorGate.cc -o xnorGate.o | ||
+ | g++ -c halfAdderGate.cc -o halfAdderGate.o | ||
+ | g++ -c fullAdderGate.cc -o fullAdderGate.o | ||
+ | |||
+ | ar src BoolLib.a *.o | ||
+ | g++ -I. notTest.cc -o notTest BoolLib.a | ||
+ | g++ -I. orTest.cc -o orTest BoolLib.a | ||
+ | g++ -I. andTest.cc -o andTest BoolLib.a | ||
+ | g++ -I. norTest.cc -o norTest BoolLib.a | ||
+ | g++ -I. norFFtest.cc -o norFFtest BoolLib.a | ||
+ | g++ -I. norFFtest2.cc -o norFFtest2 | ||
+ | g++ -I. nandTest.cc -o nandTest BoolLib.a | ||
+ | g++ -I. xorTest.cc -o xorTest BoolLib.a | ||
+ | g++ -I. nandFFtest.cc -o nandFFtest BoolLib.a | ||
+ | g++ -I. nandFFtest2.cc -o nandFFtest2 | ||
+ | g++ -I. xnorTest.cc -o xnorTest BoolLib.a | ||
+ | g++ -I. halfAdderTest.cc -o halfAddertest BoolLib.a | ||
+ | g++ -I. fullAdderTest.cc -o fullAddertest BoolLib.a | ||
+ | g++ -I. fourBitComputer.cc -o fourBitComputer BoolLib.a | ||
+ | g++ -I. fourBitComputer2.cc -o fourBitComputer2 BoolLib.a | ||
+ | |||
+ | pause | ||
+ | </ | ||
+ | \\ | ||
+ | **notGate.h**\\ | ||
+ | < | ||
+ | //notGate.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _NOTGATE_H | ||
+ | #define _NOTGATE_H | ||
+ | |||
+ | //not gate | ||
+ | |||
+ | class notGate | ||
+ | { | ||
+ | public: | ||
+ | notGate(); | ||
+ | ~notGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | bool input; | ||
+ | //bool output; | ||
+ | }; | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **notGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | |||
+ | notGate:: | ||
+ | { | ||
+ | input = false; | ||
+ | } | ||
+ | |||
+ | notGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void notGate:: | ||
+ | { | ||
+ | input = true; | ||
+ | } | ||
+ | |||
+ | void notGate:: | ||
+ | { | ||
+ | input = in; | ||
+ | } | ||
+ | |||
+ | void notGate:: | ||
+ | { | ||
+ | input = false; | ||
+ | } | ||
+ | |||
+ | bool notGate:: | ||
+ | { | ||
+ | //bool result; | ||
+ | //if (input) result = false; | ||
+ | //else result = true; | ||
+ | // | ||
+ | return(!input); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **notTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | notGate notGate1; | ||
+ | bool a = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Not Gate Truth Table" << endl; | ||
+ | cout << " ------- "<< | ||
+ | cout << "| A | O |" << endl; | ||
+ | cout << " ------- "<< | ||
+ | for (int i = 0; i <= 1; i++) | ||
+ | { | ||
+ | a = i & 0x01; | ||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // a = true; | ||
+ | // | ||
+ | //} | ||
+ | notGate1.set(a); | ||
+ | cout << "| "<< | ||
+ | cout << " -------- "<< | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **orGate.h**\\ | ||
+ | < | ||
+ | //orGate.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _ORGATE_H | ||
+ | #define _ORGATE_H | ||
+ | |||
+ | //or gate | ||
+ | |||
+ | class orGate | ||
+ | { | ||
+ | public: | ||
+ | orGate(); | ||
+ | ~orGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | bool input1; | ||
+ | bool input2; | ||
+ | //bool output; | ||
+ | }; | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **orGate.cc**\\ | ||
+ | < | ||
+ | //orGate.cc | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | |||
+ | orGate:: | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | orGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void orGate:: | ||
+ | { | ||
+ | input1 = input2 = true; | ||
+ | } | ||
+ | |||
+ | void orGate:: | ||
+ | { | ||
+ | input1 = input2 = in; | ||
+ | } | ||
+ | |||
+ | void orGate:: | ||
+ | { | ||
+ | input1 = in1; | ||
+ | input2 = in2; | ||
+ | |||
+ | } | ||
+ | |||
+ | void orGate:: | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | bool orGate:: | ||
+ | { | ||
+ | //bool result; | ||
+ | //if (input1 || input2) result = true; | ||
+ | //else result = false; | ||
+ | // | ||
+ | return(input1 || input2); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | \\ | ||
+ | **orTest.cc**\\ | ||
+ | < | ||
+ | //orTest.cc | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | orGate orGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Or Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | orGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **andGate.h**\\ | ||
+ | < | ||
+ | //andGate.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _ANDGATE_H | ||
+ | #define _ANDGATE_H | ||
+ | |||
+ | //and gate | ||
+ | |||
+ | class andGate | ||
+ | { | ||
+ | public: | ||
+ | andGate(); | ||
+ | ~andGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | bool input1; | ||
+ | bool input2; | ||
+ | }; | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **andGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | |||
+ | andGate:: | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | andGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void andGate:: | ||
+ | { | ||
+ | input1 = input2 = true; | ||
+ | } | ||
+ | |||
+ | void andGate:: | ||
+ | { | ||
+ | input1 = input2 = in; | ||
+ | } | ||
+ | |||
+ | void andGate:: | ||
+ | { | ||
+ | input1 = in1; | ||
+ | input2 = in2; | ||
+ | |||
+ | } | ||
+ | |||
+ | void andGate:: | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | bool andGate:: | ||
+ | { | ||
+ | //bool result; | ||
+ | //if (input1 && input2) result = true; | ||
+ | //else result = false; | ||
+ | // | ||
+ | return(input1 && input2); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **andTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | //#include " | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | andGate andGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "And Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | andGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **norGate.h**\\ | ||
+ | < | ||
+ | //norGate.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _NORGATE_H | ||
+ | #define _NORGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | class norGate | ||
+ | { | ||
+ | public: | ||
+ | norGate(); | ||
+ | ~norGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | orGate orGate1; | ||
+ | notGate notGate1; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **norGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | norGate:: | ||
+ | { | ||
+ | orGate1.set(false, | ||
+ | notGate1.set(orGate1.get()); | ||
+ | } | ||
+ | |||
+ | norGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void norGate:: | ||
+ | { | ||
+ | orGate1.set(true, | ||
+ | notGate1.set(orGate1.get()); | ||
+ | } | ||
+ | |||
+ | void norGate:: | ||
+ | { | ||
+ | orGate1.set(in, | ||
+ | notGate1.set(orGate1.get()); | ||
+ | } | ||
+ | |||
+ | void norGate:: | ||
+ | { | ||
+ | orGate1.set(in1, | ||
+ | notGate1.set(orGate1.get()); | ||
+ | } | ||
+ | |||
+ | void norGate:: | ||
+ | { | ||
+ | orGate1.set(false, | ||
+ | notGate1.set(orGate1.get()); | ||
+ | } | ||
+ | |||
+ | bool norGate:: | ||
+ | { | ||
+ | return(notGate1.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **norTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | norGate norGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nor Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | norGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **norFF.h**\\ | ||
+ | < | ||
+ | //norFF.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _NORFF_H | ||
+ | #define _NORFF_H | ||
+ | #include " | ||
+ | class norFF | ||
+ | { | ||
+ | public: | ||
+ | norFF(); | ||
+ | ~norFF(); | ||
+ | void setFF(bool, bool); | ||
+ | bool getQ(); | ||
+ | bool getNotQ(); | ||
+ | private: | ||
+ | //bool set; | ||
+ | //bool reset; | ||
+ | //bool Q; | ||
+ | //bool notQ; | ||
+ | norGate setGate; | ||
+ | norGate resetGate; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **norFF.cc**\\ | ||
+ | < | ||
+ | //norFF.cc | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifdef DEBUG | ||
+ | # | ||
+ | #endif | ||
+ | #include " | ||
+ | using namespace std; | ||
+ | norFF:: | ||
+ | { | ||
+ | for (int i = 1; i < 3; i++) | ||
+ | { | ||
+ | setGate.set(false, | ||
+ | resetGate.set(setGate.get(), | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | norFF:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void norFF:: | ||
+ | { | ||
+ | for (int i = 1; i < 3; i++) | ||
+ | { | ||
+ | setGate.set(Set, | ||
+ | resetGate.set(setGate.get(), | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | bool norFF:: | ||
+ | { | ||
+ | return(resetGate.get()); | ||
+ | } | ||
+ | |||
+ | bool norFF:: | ||
+ | { | ||
+ | return(setGate.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **norFFtest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include < | ||
+ | //# | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | norFF norRSFF; | ||
+ | bool set = false; | ||
+ | bool reset = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nor Flip-Flop Gate Truth Table" << endl; | ||
+ | cout << " | ||
+ | cout << "| s r | Q !Q |" << endl; | ||
+ | cout << " | ||
+ | for (int i = 1; i <= 8; i++) | ||
+ | { | ||
+ | switch(i) | ||
+ | { | ||
+ | case 1: //no change-checks initialization in constructor | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 2: //set ff | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | | ||
+ | case 3: //no change | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 4: //set ff | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 5: //no change | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 6: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 7: //no change | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 8: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | |||
+ | } | ||
+ | norRSFF.setFF(set, | ||
+ | cout << "| " << set << " " << reset << " | " << norRSFF.getQ() << " | ||
+ | } | ||
+ | cout << " | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **norFFtest2.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | void norFF (bool, bool, bool &, bool &); | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | bool set = false; | ||
+ | bool reset = false; | ||
+ | bool Q = false; | ||
+ | bool notQ = true; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nor Flip-Flop Gate Truth Table" << endl; | ||
+ | cout << " | ||
+ | cout << "| s r | Q !Q |" << endl; | ||
+ | cout << " | ||
+ | for (int i = 0; i != 6; i++) | ||
+ | { | ||
+ | switch(i) | ||
+ | { | ||
+ | case 0: | ||
+ | break; | ||
+ | case 1: | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 2: | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 3: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 4: | ||
+ | set = false; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 5: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | } | ||
+ | norFF(set, | ||
+ | cout << "| " << set << " " << reset << " | " << Q << " | ||
+ | } | ||
+ | cout << " | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | void norFF (bool set, bool reset, bool &Q, bool ¬Q) | ||
+ | { | ||
+ | for(int i = 1; i != 3; i++) | ||
+ | { | ||
+ | if(!(set | Q)) notQ = true; | ||
+ | else notQ = false; | ||
+ | if(!(reset | notQ)) Q = true; | ||
+ | else Q = false; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **nandGate.h**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _NANDGATE_H | ||
+ | #define _NANDGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | class nandGate | ||
+ | { | ||
+ | public: | ||
+ | nandGate(); | ||
+ | ~nandGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | andGate andGate1; | ||
+ | notGate notGate1; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **nandGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | nandGate:: | ||
+ | { | ||
+ | andGate1.set(false, | ||
+ | notGate1.set(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | nandGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void nandGate:: | ||
+ | { | ||
+ | andGate1.set(true, | ||
+ | notGate1.set(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | void nandGate:: | ||
+ | { | ||
+ | andGate1.set(in, | ||
+ | notGate1.set(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | void nandGate:: | ||
+ | { | ||
+ | andGate1.set(in1, | ||
+ | notGate1.set(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | void nandGate:: | ||
+ | { | ||
+ | andGate1.set(false, | ||
+ | notGate1.set(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | bool nandGate:: | ||
+ | { | ||
+ | return(notGate1.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **nandTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | nandGate nandGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nand Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | nandGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **xorGate.h**\\ | ||
+ | < | ||
+ | //xorGate.h | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _XORGATE_H | ||
+ | #define _XORGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | class xorGate | ||
+ | { | ||
+ | public: | ||
+ | xorGate(); | ||
+ | ~xorGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | notGate notGate1, notGate2; | ||
+ | andGate andGate1, andGate2; | ||
+ | orGate orGate1; | ||
+ | |||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **xorGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | xorGate:: | ||
+ | { | ||
+ | notGate1.set(false); | ||
+ | andGate1.set(notGate1.get(), | ||
+ | notGate2.set(false); | ||
+ | andGate2.set(false, | ||
+ | orGate1.set(andGate1.get(), | ||
+ | } | ||
+ | |||
+ | xorGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void xorGate:: | ||
+ | { | ||
+ | notGate1.set(true); | ||
+ | andGate1.set(notGate1.get(), | ||
+ | notGate2.set(true); | ||
+ | andGate2.set(true, | ||
+ | orGate1.set(andGate1.get(), | ||
+ | } | ||
+ | |||
+ | void xorGate:: | ||
+ | { | ||
+ | notGate1.set(in); | ||
+ | andGate1.set(notGate1.get(), | ||
+ | notGate2.set(in); | ||
+ | andGate2.set(in, | ||
+ | orGate1.set(andGate1.get(), | ||
+ | } | ||
+ | |||
+ | void xorGate:: | ||
+ | { | ||
+ | notGate1.set(in1); | ||
+ | andGate1.set(notGate1.get(), | ||
+ | notGate2.set(in2); | ||
+ | andGate2.set(in1, | ||
+ | orGate1.set(andGate1.get(), | ||
+ | } | ||
+ | |||
+ | void xorGate:: | ||
+ | { | ||
+ | notGate1.set(false); | ||
+ | andGate1.set(notGate1.get(), | ||
+ | notGate2.set(false); | ||
+ | andGate2.set(false, | ||
+ | orGate1.set(andGate1.get(), | ||
+ | } | ||
+ | |||
+ | bool xorGate:: | ||
+ | { | ||
+ | return(orGate1.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **xorTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | xorGate xorGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Xor Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | xorGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **nandFF.h**\\ | ||
+ | < | ||
+ | //nandFF.h | ||
+ | //John T. Rine | ||
+ | /// | ||
+ | #ifndef _NANDFF_H | ||
+ | #define _NANDFF_H | ||
+ | #include " | ||
+ | class nandFF | ||
+ | { | ||
+ | public: | ||
+ | nandFF(); | ||
+ | ~nandFF(); | ||
+ | void setFF(bool, bool); | ||
+ | bool getQ(); | ||
+ | bool getNotQ(); | ||
+ | private: | ||
+ | //bool set; | ||
+ | //bool reset; | ||
+ | //bool Q; | ||
+ | //bool notQ; | ||
+ | nandGate setGate; | ||
+ | nandGate resetGate; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **nandFF.cc**\\ | ||
+ | < | ||
+ | //nandFF.cc | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifdef DEBUG | ||
+ | # | ||
+ | #endif | ||
+ | #include " | ||
+ | using namespace std; | ||
+ | nandFF:: | ||
+ | { | ||
+ | for (int i = 1; i < 3; i++) | ||
+ | { | ||
+ | setGate.set(true, | ||
+ | resetGate.set(setGate.get(), | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | nandFF:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void nandFF:: | ||
+ | { | ||
+ | for (int i = 1; i < 3; i++) | ||
+ | { | ||
+ | setGate.set(Set, | ||
+ | resetGate.set(setGate.get(), | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | bool nandFF:: | ||
+ | { | ||
+ | return(setGate.get()); | ||
+ | } | ||
+ | |||
+ | bool nandFF:: | ||
+ | { | ||
+ | return(resetGate.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **nandFFtest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include < | ||
+ | //# | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | nandFF nandRSFF; | ||
+ | bool set = false; | ||
+ | bool reset = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nand Flip-Flop Gate Truth Table" << endl; | ||
+ | cout << " | ||
+ | cout << "| s r | Q !Q |" << endl; | ||
+ | cout << " | ||
+ | for (int i = 1; i <= 8; i++) | ||
+ | { | ||
+ | switch(i) | ||
+ | { | ||
+ | case 1: //no change state-checks that FF is initialized properly by constructor | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 2: //set FF | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 3: //no change | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | | ||
+ | case 4: //set ff | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 5: //no change | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 6: | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 7: //no change | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 8: | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | break; | ||
+ | |||
+ | } | ||
+ | nandRSFF.setFF(set, | ||
+ | cout << "| " << set << " " << reset << " | " << nandRSFF.getQ() << " | ||
+ | } | ||
+ | cout << " | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **nandFFtest2.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | void nandFF (bool, bool, bool &, bool &); | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | bool set = true; | ||
+ | bool reset = false; | ||
+ | bool Q = false; | ||
+ | bool notQ = true; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Nand Flip-Flop Gate Truth Table" << endl; | ||
+ | cout << " | ||
+ | cout << "| s r | Q !Q |" << endl; | ||
+ | cout << " | ||
+ | for (int i = 0; i != 6; i++) | ||
+ | { | ||
+ | switch(i) | ||
+ | { | ||
+ | case 0: | ||
+ | break; | ||
+ | case 1: | ||
+ | set = true; | ||
+ | reset = false; | ||
+ | break; | ||
+ | case 2: | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 3: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 4: | ||
+ | set = true; | ||
+ | reset = true; | ||
+ | break; | ||
+ | case 5: | ||
+ | set = false; | ||
+ | reset = true; | ||
+ | break; | ||
+ | } | ||
+ | nandFF(set, | ||
+ | cout << "| " << set << " " << reset << " | " << Q << " | ||
+ | } | ||
+ | cout << " | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | |||
+ | void nandFF (bool set, bool reset, bool &Q, bool ¬Q) | ||
+ | { | ||
+ | for(int i = 1; i < 3; i++) | ||
+ | { | ||
+ | if(!(set & notQ)) Q = true; | ||
+ | else Q = false; | ||
+ | if(!(reset & Q)) notQ = true; | ||
+ | else notQ = false; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **xnorGate.h**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _XNORGATE_H | ||
+ | #define _XNORGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | class xnorGate | ||
+ | { | ||
+ | public: | ||
+ | xnorGate(); | ||
+ | ~xnorGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool get(); | ||
+ | private: | ||
+ | xorGate xorGate1; | ||
+ | notGate notGate1; | ||
+ | |||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **xnorGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | xnorGate:: | ||
+ | { | ||
+ | | ||
+ | notGate1.set(xorGate1.get()); | ||
+ | } | ||
+ | |||
+ | xnorGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void xnorGate:: | ||
+ | { | ||
+ | | ||
+ | notGate1.set(xorGate1.get()); | ||
+ | } | ||
+ | |||
+ | void xnorGate:: | ||
+ | { | ||
+ | | ||
+ | notGate1.set(xorGate1.get()); | ||
+ | } | ||
+ | |||
+ | void xnorGate:: | ||
+ | { | ||
+ | xorGate1.set(in1, | ||
+ | notGate1.set(xorGate1.get()); | ||
+ | |||
+ | } | ||
+ | |||
+ | void xnorGate:: | ||
+ | { | ||
+ | xorGate1.set(false, | ||
+ | notGate1.set(xorGate1.get()); | ||
+ | } | ||
+ | |||
+ | bool xnorGate:: | ||
+ | { | ||
+ | return(notGate1.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **xnorTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | xnorGate xnorGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << "Xnor Gate Truth Table" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | cout << "| A B | O |" << endl; | ||
+ | cout << " ----------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | xnorGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " ----------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **halfAdderGate.h**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _HALFADDERGATE_H | ||
+ | #define _HALFADDERGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | class halfAdderGate | ||
+ | { | ||
+ | public: | ||
+ | halfAdderGate(); | ||
+ | ~halfAdderGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | void reset(); | ||
+ | bool getSum(); | ||
+ | bool getCarry(); | ||
+ | private: | ||
+ | xorGate xorGate1; | ||
+ | andGate andGate1; | ||
+ | |||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **halfAdderGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | halfAdderGate:: | ||
+ | { | ||
+ | xorGate1.set(false, | ||
+ | andGate1.set(false, | ||
+ | } | ||
+ | |||
+ | halfAdderGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void halfAdderGate:: | ||
+ | { | ||
+ | xorGate1.set(true, | ||
+ | andGate1.set(true, | ||
+ | } | ||
+ | |||
+ | void halfAdderGate:: | ||
+ | { | ||
+ | xorGate1.set(in, | ||
+ | andGate1.set(in, | ||
+ | } | ||
+ | |||
+ | void halfAdderGate:: | ||
+ | { | ||
+ | xorGate1.set(in1, | ||
+ | andGate1.set(in1, | ||
+ | |||
+ | } | ||
+ | |||
+ | void halfAdderGate:: | ||
+ | { | ||
+ | xorGate1.set(false, | ||
+ | andGate1.set(false, | ||
+ | } | ||
+ | |||
+ | bool halfAdderGate:: | ||
+ | { | ||
+ | return(xorGate1.get()); | ||
+ | } | ||
+ | |||
+ | bool halfAdderGate:: | ||
+ | { | ||
+ | return(andGate1.get()); | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | \\ | ||
+ | **halfAdderTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | halfAdderGate halfAdderGate1; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | |||
+ | cout << " | ||
+ | cout << " -------------- "<< | ||
+ | cout << "| A B | S C |" << endl; | ||
+ | cout << " -------------- "<< | ||
+ | for (int i = 0; i != 4; i++) | ||
+ | { | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | halfAdderGate1.set(a, | ||
+ | cout << "| "<< | ||
+ | cout << " -------------- " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **fullAdderGate.h**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #ifndef _FULLADDERGATE_H | ||
+ | #define _FULLADDERGATE_H | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | class fullAdderGate | ||
+ | { | ||
+ | public: | ||
+ | fullAdderGate(); | ||
+ | ~fullAdderGate(); | ||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool, bool); | ||
+ | void reset(); | ||
+ | bool getSum(); | ||
+ | bool getCarry(); | ||
+ | private: | ||
+ | halfAdderGate halfAdderGate1; | ||
+ | halfAdderGate halfAdderGate2; | ||
+ | orGate orGate1; | ||
+ | |||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **fullAdderGate.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | |||
+ | fullAdderGate:: | ||
+ | { | ||
+ | halfAdderGate1.set(false, | ||
+ | halfAdderGate2.set(false, | ||
+ | orGate1.set(halfAdderGate1.getCarry(), | ||
+ | } | ||
+ | |||
+ | fullAdderGate:: | ||
+ | { | ||
+ | } | ||
+ | |||
+ | void fullAdderGate:: | ||
+ | { | ||
+ | halfAdderGate1.set(true, | ||
+ | halfAdderGate2.set(true, | ||
+ | orGate1.set(halfAdderGate1.getCarry(), | ||
+ | } | ||
+ | |||
+ | void fullAdderGate:: | ||
+ | { | ||
+ | halfAdderGate1.set(in, | ||
+ | halfAdderGate2.set(in, | ||
+ | orGate1.set(halfAdderGate1.getCarry(), | ||
+ | } | ||
+ | |||
+ | void fullAdderGate:: | ||
+ | { | ||
+ | halfAdderGate1.set(in1, | ||
+ | halfAdderGate2.set(cin, | ||
+ | orGate1.set(halfAdderGate1.getCarry(), | ||
+ | } | ||
+ | |||
+ | void fullAdderGate:: | ||
+ | { | ||
+ | halfAdderGate1.set(false, | ||
+ | halfAdderGate2.set(false, | ||
+ | orGate1.set(halfAdderGate1.getCarry(), | ||
+ | } | ||
+ | |||
+ | bool fullAdderGate:: | ||
+ | { | ||
+ | return(halfAdderGate2.getSum()); | ||
+ | } | ||
+ | |||
+ | bool fullAdderGate:: | ||
+ | { | ||
+ | return(orGate1.get()); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **fullAdderTest.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | #include " | ||
+ | #include < | ||
+ | //# | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | fullAdderGate fullAdderGate1; | ||
+ | bool cin = false; | ||
+ | bool a = false; | ||
+ | bool b = false; | ||
+ | cout << endl << "TRUE is: " << true << "; "; | ||
+ | cout << "FALSE is: " << false << endl << endl; | ||
+ | cout << " | ||
+ | cout << " ------------------ "<< | ||
+ | cout << "| Cin A B | S C |" << endl; | ||
+ | cout << " ------------------ "<< | ||
+ | for (int i = 0; i <= 7; i++) | ||
+ | { | ||
+ | cin = i & 0x04; | ||
+ | a = i & 0x02; | ||
+ | b = i & 0x01; | ||
+ | |||
+ | // | ||
+ | //{ | ||
+ | // case 0: | ||
+ | // | ||
+ | // case 1: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 2: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 3: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 4: | ||
+ | // cin = true; | ||
+ | // a = false; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 5: | ||
+ | // b = true; | ||
+ | // | ||
+ | // case 6: | ||
+ | // a = true; | ||
+ | // b = false; | ||
+ | // | ||
+ | // case 7: | ||
+ | // b = true; | ||
+ | // | ||
+ | //} | ||
+ | fullAdderGate1.set(cin, | ||
+ | cout << "| "<< | ||
+ | cout << " ------------------ " << endl; | ||
+ | } | ||
+ | // | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **fourBitComputer.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | # | ||
+ | # | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(int argc, char ** argv) | ||
+ | { | ||
+ | int bits = 4; | ||
+ | fullAdderGate bit[bits]; | ||
+ | if (*(argv + 1) == string(" | ||
+ | { | ||
+ | cout << " | ||
+ | cout << "1st binary field-adden 1" << endl; | ||
+ | cout << "2nd binary field-adden 2" << endl; | ||
+ | exit(0); | ||
+ | } | ||
+ | else if (*(argv + 1) == string(" | ||
+ | { | ||
+ | cout << " | ||
+ | exit(0); | ||
+ | } | ||
+ | else if (argc != 3) | ||
+ | { | ||
+ | if (argc < 3) cout << " | ||
+ | else if (argc > 3) cout << "too many command line arguments"; | ||
+ | exit(1); | ||
+ | } | ||
+ | int ii = bits - 1; | ||
+ | bool cin = false; | ||
+ | for(int i = 0; i <= bits - 1; i++) | ||
+ | { | ||
+ | if (i > 0) cin = bit[i - 1].getCarry(); | ||
+ | bit[i].set(cin, | ||
+ | ii--; | ||
+ | } | ||
+ | cout << bit[bits - 1].getCarry() << " "; | ||
+ | for (int i = bits - 1; i >= 0; i--) | ||
+ | { | ||
+ | cout << bit[i].getSum(); | ||
+ | } | ||
+ | cout << endl; | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **fourBitComputer2.cc**\\ | ||
+ | < | ||
+ | // | ||
+ | //John T. Rine | ||
+ | // | ||
+ | # | ||
+ | # | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | using namespace std; | ||
+ | |||
+ | int main(int argc, char ** argv) | ||
+ | { | ||
+ | int bits = 4; | ||
+ | int fields = 4; | ||
+ | fullAdderGate bit[bits]; | ||
+ | xorGate compliment[bits]; | ||
+ | |||
+ | if (*(argv + 1) == string(" | ||
+ | { | ||
+ | cout << " | ||
+ | cout << "1st binary field-operation" | ||
+ | cout << "2nd binary field-adden 1/ | ||
+ | cout << "3rd binary field-adden 2/ | ||
+ | cout << endl; | ||
+ | cout << " | ||
+ | cout << "0 = add" << endl; | ||
+ | cout << "1 = subtract" | ||
+ | cout << endl; | ||
+ | cout << " | ||
+ | cout << " | ||
+ | |||
+ | exit(0); | ||
+ | } | ||
+ | else if (*(argv + 1) == string(" | ||
+ | { | ||
+ | cout << " | ||
+ | exit(0); | ||
+ | } | ||
+ | else if (argc != fields) | ||
+ | { | ||
+ | if (argc < fields) cout << " | ||
+ | else if (argc > fields) cout << "too many command line arguments"; | ||
+ | exit(1); | ||
+ | } | ||
+ | int ii = bits - 1; | ||
+ | bool cin = false; | ||
+ | for(int i = 0; i <= bits - 1; i++) | ||
+ | { | ||
+ | compliment[i].set(*(*(argv + 1) + 0) & 0x01, *(*(argv + 3) + ii) & 0x01); | ||
+ | if (i == 0) cin = *(*(argv + 1) + 0) & 0x01; | ||
+ | else cin = bit[i - 1].getCarry(); | ||
+ | bit[i].set(cin, | ||
+ | ii--; | ||
+ | } | ||
+ | cout << bit[bits - 1].getCarry() << " "; | ||
+ | for (int i = bits - 1; i >= 0; i--) | ||
+ | { | ||
+ | cout << bit[i].getSum(); | ||
+ | } | ||
+ | cout << endl; | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | ======Compilation====== | ||
+ | **Compilation (makeLogicandCPU.bat)**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | |||
+ | C: | ||
+ | derGate.o | ||
+ | |||
+ | C: | ||
+ | derGate.o | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | lLib.a | ||
+ | |||
+ | C: | ||
+ | ib.a | ||
+ | |||
+ | C: | ||
+ | lLib.a | ||
+ | |||
+ | C: | ||
+ | lLib.a | ||
+ | |||
+ | C: | ||
+ | | ||
+ | |||
+ | C: | ||
+ | t2 | ||
+ | |||
+ | C: | ||
+ | oolLib.a | ||
+ | |||
+ | C: | ||
+ | lLib.a | ||
+ | |||
+ | C: | ||
+ | st BoolLib.a | ||
+ | |||
+ | C: | ||
+ | est2 | ||
+ | |||
+ | C: | ||
+ | oolLib.a | ||
+ | |||
+ | C: | ||
+ | ddertest BoolLib.a | ||
+ | |||
+ | C: | ||
+ | ddertest BoolLib.a | ||
+ | |||
+ | C: | ||
+ | rBitComputer BoolLib.a | ||
+ | |||
+ | C: | ||
+ | urBitComputer2 BoolLib.a | ||
+ | |||
+ | C: | ||
+ | Press any key to continue . . . | ||
+ | </ | ||
+ | ======Execution====== | ||
+ | **Execution of notTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Not Gate Truth Table | ||
+ | | ||
+ | | A | O | | ||
+ | | ||
+ | | 0 | 1 | | ||
+ | | ||
+ | | 1 | 0 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of orTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Or Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 0 | | ||
+ | | ||
+ | | 0 1 | 1 | | ||
+ | | ||
+ | | 1 0 | 1 | | ||
+ | | ||
+ | | 1 1 | 1 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of andTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | And Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 0 | | ||
+ | | ||
+ | | 0 1 | 0 | | ||
+ | | ||
+ | | 1 0 | 0 | | ||
+ | | ||
+ | | 1 1 | 1 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of norTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nor Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 1 | | ||
+ | | ||
+ | | 0 1 | 0 | | ||
+ | | ||
+ | | 1 0 | 0 | | ||
+ | | ||
+ | | 1 1 | 0 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of norFFtest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nor Flip-Flop Gate Truth Table | ||
+ | -------------- | ||
+ | | s r | Q !Q | | ||
+ | -------------- | ||
+ | | 0 0 | 0 1 | | ||
+ | | 1 0 | 1 0 | | ||
+ | | 0 0 | 1 0 | | ||
+ | | 1 0 | 1 0 | | ||
+ | | 0 0 | 1 0 | | ||
+ | | 0 1 | 0 1 | | ||
+ | | 0 0 | 0 1 | | ||
+ | | 0 1 | 0 1 | | ||
+ | -------------- | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of norFFtest2.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nor Flip-Flop Gate Truth Table | ||
+ | -------------- | ||
+ | | s r | Q !Q | | ||
+ | -------------- | ||
+ | | 0 0 | 0 1 | | ||
+ | | 1 0 | 1 0 | | ||
+ | | 0 0 | 1 0 | | ||
+ | | 0 1 | 0 1 | | ||
+ | | 0 0 | 0 1 | | ||
+ | | 0 1 | 0 1 | | ||
+ | -------------- | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of nandTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nand Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 1 | | ||
+ | | ||
+ | | 0 1 | 1 | | ||
+ | | ||
+ | | 1 0 | 1 | | ||
+ | | ||
+ | | 1 1 | 0 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of xorTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Xor Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 0 | | ||
+ | | ||
+ | | 0 1 | 1 | | ||
+ | | ||
+ | | 1 0 | 1 | | ||
+ | | ||
+ | | 1 1 | 0 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of nandFFtest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nand Flip-Flop Gate Truth Table | ||
+ | -------------- | ||
+ | | s r | Q !Q | | ||
+ | -------------- | ||
+ | | 1 1 | 0 1 | | ||
+ | | 0 1 | 1 0 | | ||
+ | | 1 1 | 1 0 | | ||
+ | | 0 1 | 1 0 | | ||
+ | | 1 1 | 1 0 | | ||
+ | | 1 0 | 0 1 | | ||
+ | | 1 1 | 0 1 | | ||
+ | | 1 0 | 0 1 | | ||
+ | -------------- | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of nandFFtest2.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Nand Flip-Flop Gate Truth Table | ||
+ | -------------- | ||
+ | | s r | Q !Q | | ||
+ | -------------- | ||
+ | | 1 0 | 0 1 | | ||
+ | | 1 0 | 0 1 | | ||
+ | | 1 1 | 0 1 | | ||
+ | | 0 1 | 1 0 | | ||
+ | | 1 1 | 1 0 | | ||
+ | | 0 1 | 1 0 | | ||
+ | -------------- | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of xnorTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Xnor Gate Truth Table | ||
+ | | ||
+ | | A B | O | | ||
+ | | ||
+ | | 0 0 | 1 | | ||
+ | | ||
+ | | 0 1 | 0 | | ||
+ | | ||
+ | | 1 0 | 0 | | ||
+ | | ||
+ | | 1 1 | 1 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of halfAdderTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Half-Adder Gate Truth Table | ||
+ | | ||
+ | | A B | S C | | ||
+ | | ||
+ | | 0 0 | 0 0 | | ||
+ | | ||
+ | | 0 1 | 1 0 | | ||
+ | | ||
+ | | 1 0 | 1 0 | | ||
+ | | ||
+ | | 1 1 | 0 1 | | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of fullAdderTest.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | |||
+ | TRUE is: 1; FALSE is: 0 | ||
+ | |||
+ | Full-Adder Gate Truth Table | ||
+ | | ||
+ | | Cin A B | S C | | ||
+ | | ||
+ | | 0 | ||
+ | | ||
+ | | 0 | ||
+ | | ||
+ | | 0 | ||
+ | | ||
+ | | 0 | ||
+ | | ||
+ | | 1 | ||
+ | | ||
+ | | 1 | ||
+ | | ||
+ | | 1 | ||
+ | | ||
+ | | 1 | ||
+ | | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of fourBitComputer.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | Usage: fourBitComputer [1st 4-bit binary field] [2nd 4-bit binary field] | ||
+ | 1st binary field-adden 1 | ||
+ | 2nd binary field-adden 2 | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | 0 0001 | ||
+ | |||
+ | C: | ||
+ | 0 1111 | ||
+ | |||
+ | C: | ||
+ | 1 0000 | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | **Execution of fourBitComputer2.exe**\\ | ||
+ | <cli> | ||
+ | |||
+ | C: | ||
+ | Usage: fourBitComputer [1-bit binary field] [4-bit binary field] [4-bit binary f | ||
+ | ield] | ||
+ | 1st binary field-operation | ||
+ | 2nd binary field-adden 1/minuend | ||
+ | 3rd binary field-adden 2/ | ||
+ | |||
+ | Commands: | ||
+ | 0 = add | ||
+ | 1 = subtract | ||
+ | |||
+ | Returns: | ||
+ | carry/not borrow | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | \\ | ||
+ | <cli> | ||
+ | Microsoft Windows [Version 6.1.7601] | ||
+ | Copyright (c) 2009 Microsoft Corporation. | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | |||
+ | C: | ||
+ | 0 0010 | ||
+ | |||
+ | C: | ||
+ | 1 0000 | ||
+ | |||
+ | C: | ||
+ | 1 1110 | ||
+ | |||
+ | C: | ||
+ | 1 0000 | ||
+ | |||
+ | C: | ||
+ | 1 0000 | ||
+ | |||
+ | C: | ||
+ | 0 0001 | ||
+ | |||
+ | C: | ||
+ | </ | ||
+ | ======References====== | ||
+ | * http:// | ||
+ | * http:// |