User Tools

Site Tools


user:jr018429:portfolio:orclassdocumentation

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
user:jr018429:portfolio:orclassdocumentation [2011/05/18 23:38] jr018429user:jr018429:portfolio:orclassdocumentation [2011/05/18 23:44] (current) jr018429
Line 1: Line 1:
 +======OR class======
  
 +The OR class implements a functioning logical OR gate for use with our CPU simulator.
 +
 +=====OR() constructor=====
 +
 +<code c++>
 +OR myOrGate;
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  OR()  |  none  |  pointer/variable instantiation of the newly allocated OR gate  |
 +
 +OR() is the parameterless constructor that is responsible for creating a new instance of an OR.
 +
 +=====reset()=====
 +reset() will reset both inputs coming into the OR to FALSE values.
 +
 +<code c++>
 +myOrGate.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++>
 +myOrGate.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;
 +
 +...
 +
 +myOrGate.set(a, b);
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  void set()  |  bool, bool  |  none  |
 +
 +=====setvalue()=====
 +get() will retrieve the output of the OR.
 +
 +<code c++>
 +bool output = myOrGate.get();
 +</code>
 +
 +^  Function  ^  Parameter(s)  ^  Return value  |
 +|  bool get(int)  |  none  |  boolean value of gate's output  |
 +\\
 +**or.h**\\
 +<code>
 +#ifndef _OR_H
 +#define _OR_H
 +class OR
 +{
 +        public:
 +                OR();
 +
 +                void set();
 +                void set(bool);
 +                void set(bool, bool);
 +                bool get();
 +
 +        private:
 +                bool input1;
 +                bool input2;
 +};
 +#endif
 +</code>
 +\\
 +**or.cc**\\
 +<code>
 +#include "or.h"
 +
 +OR::OR()
 +{
 +        input1 = input2 = false;
 +}
 +
 +void OR::set()
 +{
 +        input1 = input2 = false;
 +}
 +
 +void OR::set(bool value)
 +{
 +        input1 = input2 = value;
 +}
 +
 +void OR::set(bool val1, bool val2)
 +{
 +        input1 = val1;
 +        input2 = val2;
 +}
 +
 +bool OR::get()
 +{
 +        bool result = false;
 +        if ((input1 == true) || (input2 == true))
 +        {
 +                result = true;
 +        }
 +
 +        return (result);
 +}
 +</code>
 +\\
 +**ortest.cc**\\
 +<code>
 +#include <cstdio>
 +#include "or.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");
 +
 +        OR myOrGate;
 +
 +        printf(" a b | x \n");
 +        printf("-----+---\n");
 +
 +        for(int temp = 0; temp <=3; temp++)
 +        {
 +                a = temp & 0x02;
 +                b = temp & 0x01;
 +                //if(temp & 0x02) 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;
 +                ////}
 +                myOrGate.set(a, b);
 +                printf(" %d %d | %d\n", a, b, myOrGate.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>