User Tools

Site Tools


user:jr018429:portfolio:xorclassdocumentation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
user:jr018429:portfolio:xorclassdocumentation [2011/05/13 13:35] – created jr018429user: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;
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  XOR()  |  none  |  pointer/variable instantiation of the newly allocated XOR gate  |
 +
 +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();
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  void reset()  |  no parameters  |  none  |
 +
 +=====set(bool)=====
 +set(bool) will take the parameter and set both inputs to that value.
 +
 +<code c++>
 +myXorGate.set(true);
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  void set()  |  bool  |  none  |
 +
 +=====set(bool, 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, b);
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  void set()  |  bool, bool  |  none  |
 +
 +=====setvalue()=====
 +get() will retrieve the output of the XOR.
 +
 +<code c++>
 +bool output = myXorGate.get();
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  bool get(int)  |  none  |  boolean value of gate's output  |
 +\\
 +**xor.h**\\
 +<code>
 +#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
 +</code>
 +\\
 +**xor.cc**\\
 +<code>
 +#include "xor.h"
 +
 +XOR::XOR()
 +{
 +        input1 = input2 = false;
 +}
 +
 +void XOR::set()
 +{
 +        input1 = input2 = false;
 +}
 +
 +void XOR::set(bool value)
 +{
 +        input1 = input2 = value;
 +}
 +
 +void XOR::set(bool val1, bool val2)
 +{
 +        input1 = val1;
 +        input2 = val2;
 +}
 +
 +bool XOR::get()
 +{
 +        bool result = false;
 +        if ((input1 == true && input2 == false) || (input1 == false && input2 == true))
 +        {
 +                result = true;
 +        }
 +
 +        return (result);
 +}
 +</code>
 +\\
 +**xortest.cc**\\
 +<code>
 +#include <cstdio>
 +#include "xor.h"
 +
 +int main()
 +{
 +        bool a, b;
 +        a = true, b = false;
 +
 +        printf("--------------------\n");
 +        printf("TRUE is: %d\n", true);
 +        printf("FALSE is: %d\n", false);
 +        printf("--------------------\n\n");
 +
 +        XOR myXorGate;
 +
 +        printf(" a b | x \n");
 +        printf("-----+---\n");
 +
 +        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;
 +                ////switch(temp)
 +                ////{
 +                ////    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, b);
 +                printf(" %d %d | %d\n", a, b, myXorGate.get());
 +        }
 +        printf("---------\n");
 +        return(0);
 +}
 +</code>
 +\\
 +**Makefile**\\
 +<code>
 +CXX = g++ $(CXXFLAGS) $(INC)
 +CXXFLAGS = -Wall
 +INC = -I ../../include/
 +SRC = xor.cc
 +OBJ = $(SRC:.cc=.o)
 +all: $(SRC) $(OBJ)
 +
 +debug: CXX += -DDEBUG -g
 +debug: DEBUG = debug
 +debug: $(SRC) $(BIN)
 +
 +.cc.o:
 +ifneq ($(MAKECMDGOALS),debug)
 +        @printf "[B]   %-20s ... " "$<"
 +        @$(CXX) -c $< && echo "OK" || echo "FAIL"
 +else
 +        $(CXX) -c $<
 +endif
 +
 +clean:
 +        rm -f *.o $(OBJ) core
 +</code>