This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
user:jr018429:portfolio:xorclassdocumentation [2011/05/13 13:35] – created jr018429 | user:jr018429:portfolio:xorclassdocumentation [2011/05/18 23:51] (current) – jr018429 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======XOR class====== | ||
+ | The XOR class implements a functioning logical XOR gate for use with our CPU simulator. | ||
+ | |||
+ | =====XOR() constructor===== | ||
+ | |||
+ | <code c++> | ||
+ | XOR myXorGate; | ||
+ | </ | ||
+ | |||
+ | ^ Function | ||
+ | | XOR() | none | pointer/ | ||
+ | |||
+ | XOR() is the parameterless constructor that is responsible for creating a new instance of an XOR. | ||
+ | |||
+ | =====reset()===== | ||
+ | reset() will reset both inputs coming into the XOR to FALSE values. | ||
+ | |||
+ | <code c++> | ||
+ | myXorGate.reset(); | ||
+ | </ | ||
+ | |||
+ | ^ Function | ||
+ | | void reset() | ||
+ | |||
+ | =====set(bool)===== | ||
+ | set(bool) will take the parameter and set both inputs to that value. | ||
+ | |||
+ | <code c++> | ||
+ | myXorGate.set(true); | ||
+ | </ | ||
+ | |||
+ | ^ Function | ||
+ | | void set() | bool | none | | ||
+ | |||
+ | =====set(bool, | ||
+ | set(bool, bool) will take the parameter and set each input to a unique value. | ||
+ | |||
+ | <code c++> | ||
+ | bool a = true; | ||
+ | bool b = false; | ||
+ | |||
+ | ... | ||
+ | |||
+ | myXorGate.set(a, | ||
+ | </ | ||
+ | |||
+ | ^ Function | ||
+ | | void set() | bool, bool | none | | ||
+ | |||
+ | =====setvalue()===== | ||
+ | get() will retrieve the output of the XOR. | ||
+ | |||
+ | <code c++> | ||
+ | bool output = myXorGate.get(); | ||
+ | </ | ||
+ | |||
+ | ^ Function | ||
+ | | bool get(int) | ||
+ | \\ | ||
+ | **xor.h**\\ | ||
+ | < | ||
+ | #ifndef _XOR_H | ||
+ | #define _XOR_H | ||
+ | class XOR | ||
+ | { | ||
+ | public: | ||
+ | XOR(); | ||
+ | |||
+ | void set(); | ||
+ | void set(bool); | ||
+ | void set(bool, bool); | ||
+ | bool get(); | ||
+ | |||
+ | private: | ||
+ | bool input1; | ||
+ | bool input2; | ||
+ | }; | ||
+ | #endif | ||
+ | </ | ||
+ | \\ | ||
+ | **xor.cc**\\ | ||
+ | < | ||
+ | #include " | ||
+ | |||
+ | XOR::XOR() | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | void XOR::set() | ||
+ | { | ||
+ | input1 = input2 = false; | ||
+ | } | ||
+ | |||
+ | void XOR:: | ||
+ | { | ||
+ | input1 = input2 = value; | ||
+ | } | ||
+ | |||
+ | void XOR:: | ||
+ | { | ||
+ | input1 = val1; | ||
+ | input2 = val2; | ||
+ | } | ||
+ | |||
+ | bool XOR::get() | ||
+ | { | ||
+ | bool result = false; | ||
+ | if ((input1 == true && input2 == false) || (input1 == false && input2 == true)) | ||
+ | { | ||
+ | result = true; | ||
+ | } | ||
+ | |||
+ | return (result); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **xortest.cc**\\ | ||
+ | < | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | bool a, b; | ||
+ | a = true, b = false; | ||
+ | |||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | XOR myXorGate; | ||
+ | |||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | for(int temp = 0; temp <=3; temp++) | ||
+ | { | ||
+ | a = temp & 0x02; | ||
+ | b = temp & 0x01; | ||
+ | //if (temp & 0x2) a = true; | ||
+ | //else a = false; | ||
+ | //if (temp & 0x01) b = true; | ||
+ | //else b = false; | ||
+ | //// | ||
+ | ////{ | ||
+ | //// case 0: | ||
+ | //// a = false; | ||
+ | //// b = false; | ||
+ | //// break; | ||
+ | //// case 1: | ||
+ | //// a = false; | ||
+ | //// b = true; | ||
+ | //// break; | ||
+ | //// case 2: | ||
+ | //// a = true; | ||
+ | //// b = false; | ||
+ | //// break; | ||
+ | //// case 3: | ||
+ | //// a = true; | ||
+ | //// b = true; | ||
+ | //// break; | ||
+ | ////} | ||
+ | myXorGate.set(a, | ||
+ | printf(" | ||
+ | } | ||
+ | printf(" | ||
+ | return(0); | ||
+ | } | ||
+ | </ | ||
+ | \\ | ||
+ | **Makefile**\\ | ||
+ | < | ||
+ | CXX = g++ $(CXXFLAGS) $(INC) | ||
+ | CXXFLAGS = -Wall | ||
+ | INC = -I ../ | ||
+ | SRC = xor.cc | ||
+ | OBJ = $(SRC: | ||
+ | all: $(SRC) $(OBJ) | ||
+ | |||
+ | debug: CXX += -DDEBUG -g | ||
+ | debug: DEBUG = debug | ||
+ | debug: $(SRC) $(BIN) | ||
+ | |||
+ | .cc.o: | ||
+ | ifneq ($(MAKECMDGOALS), | ||
+ | @printf " | ||
+ | @$(CXX) -c $< && echo " | ||
+ | else | ||
+ | $(CXX) -c $< | ||
+ | endif | ||
+ | |||
+ | clean: | ||
+ | rm -f *.o $(OBJ) core | ||
+ | </ |