User Tools

Site Tools


user:jr018429:portfolio:orclassdocumentation

OR class

The OR class implements a functioning logical OR gate for use with our CPU simulator.

OR() constructor

OR myOrGate;
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.

myOrGate.reset();
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.

myOrGate.set(true);
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.

bool a = true;
bool b = false;
 
...
 
myOrGate.set(a, b);
Function Parameter(s) Return value
void set() bool, bool none

setvalue()

get() will retrieve the output of the OR.

bool output = myOrGate.get();
Function Parameter(s) Return value
bool get(int) none boolean value of gate's output


or.h

#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


or.cc

#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);
}


ortest.cc

#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);
}


Makefile

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
user/jr018429/portfolio/orclassdocumentation.txt · Last modified: 2011/05/18 19:44 by jr018429