How would I set up gateAnd(), gateOr()...etc...
I have never tried to replicate these operations with a program, and also first time using c, only have used Java previously..
I also will have to setup halfAdder, and fullAdder.
Here is the code:
Code:
#include "stdlib.h"
#include "assert.h"
#include "stdio.h"
#include "circuit.h"
int main(int argc, char * argv[])
{
struct gate * g = gateInput("Type an Integer");
gatePrint(g);
return 0;
}
struct gate * gateInput(char * prompt)
{
int i;
printf(prompt);
scanf("%d", &i);
return gateConstant(i);
}
struct gate * gateConstant (int value)
{
struct gate * r = (struct gate *) malloc(sizeof(struct gate));
assert(r != 0);
if (value == 0)
return gateZero();
if (value == 1)
return gateOne();
}
struct gate * gateZero()
{
struct gate * r = (struct gate *) malloc(sizeof(struct gate));
assert(r != 0);
r -> gateType = ConstantZeroGate;
return r;
}
struct gate * gateOne()
{
struct gate * r = (struct gate *) malloc(sizeof(struct gate));
assert(r != 0);
r -> gateType = ConstantOneGate;
return r;
}
void gatePrint (struct gate * e)
{
printf("The entered Value: %d \n",*e);
}
int gateEval (struct gate * e)
{
}
void intToBit (int value, int * eights, int * fours, int * twos, int * ones)
{
assert ((value >= 0) && (value < 16));
*ones = value % 2;
}
struct gate * gateNot(struct gate * arg)
{
}
struct gate * gateAnd(struct gate * left, struct gate * right)
{
}
struct gate * gateOr(struct gate * left, struct gate * right)
{
}
struct gate * gateXor(struct gate * left, struct gate right)
{
}
void halfAdder(struct gate * left, struct gate * right, struct * carryin, struct gate **sum)
{
}