Reputation: 1
i'm a first year computer science student and i've found myself stuck on one particular part of the assignment. We are tasked to create several gates in hack's HDL in various ways. I had little to no trouble with most of them but i found myself stuck on the 8 way OR.
No matter how many times i've tried to come up with a solution, the test script always fails for the input values 00000001. I know why it does that and why it doesn't work, but i have zero clue about what i could do to get around it
Here's some iterations of the code i've tried using:
//Latest one
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Nand(a = in[0], b = in[1], out = or1);
Nand(a = in[2], b = in[3], out = or2);
Nand(a = in[4], b = in[5], out = or3);
Nand(a = in[6], b = in[7], out = or4);
Nand(a = or1, b = or2, out = inA);
//Nand(a = inA, b = inA, out = notINA);
Nand(a = or3, b = or4, out = inB);
Nand(a = inA, b = inB, out = out);
//Nand(a = outpre, b = outpre, out = out);//i commented out these because i was trying to negate one of the inputs in the final Nand so that there wouldn't be a case where both 1s become zeros
}
//This is the iteration i've been stuck on trying to get working for the longest
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Nand(a = in[0], b = in[0], out = not0);
Nand(a = in[1], b = in[1], out = not1);
Nand(a = in[2], b = in[2], out = not2);
Nand(a = in[3], b = in[3], out = not3);
Nand(a = in[4], b = in[4], out = not4);
Nand(a = in[5], b = in[5], out = not5);
Nand(a = in[6], b = in[6], out = not6);
Nand(a = in[7], b = in[7], out = not7);
Nand(a = not0, b = not1, out = mid1);
Nand(a = not2, b = not3, out = mid2);
Nand(a = not4, b = not5, out = mid3);
Nand(a = not6, b = not7, out = mid4);
Nand(a = mid1, b = mid2, out = orA);
Nand(a = mid3, b = mid4, out = orB);
Nand(a = orA, b = orB, out = out);
}
The amount of headaches this has given me is embarassing
Like i mentioned in the code comments i've first tried to negate one of the final inputs, then i tried to negate some more or to change up my grouping logic all with no luck
Upvotes: 0
Views: 75
Reputation: 6468
First principals: de morgan's law says A or B == (not A) NAND (not B) expanding that out for all 8 instead of just two might have a way to reduce gates, but the direct approach would be to realize A or B or C or D or ... H == (A or B) or (C or D) or (...) to get the first set you should do what you're doing above but then when you want to combine those mid values, you need to negate them and use a nand... i.e.
//This is the iteration i've been stuck on trying to get working for the longest
CHIP Or8Way {
IN in[8];
OUT out;
PARTS:
Nand(a = in[0], b = in[0], out = not0);
Nand(a = in[1], b = in[1], out = not1);
Nand(a = in[2], b = in[2], out = not2);
Nand(a = in[3], b = in[3], out = not3);
Nand(a = in[4], b = in[4], out = not4);
Nand(a = in[5], b = in[5], out = not5);
Nand(a = in[6], b = in[6], out = not6);
Nand(a = in[7], b = in[7], out = not7);
Nand(a = not0, b = not1, out = mid1);
Nand(a = not2, b = not3, out = mid2);
Nand(a = not4, b = not5, out = mid3);
Nand(a = not6, b = not7, out = mid4);
//change from your anser:
Nand(a = mid1, b = mid1, out = not_mid1);
...
Nand(a = not_mid1, b = not_mid2, out = mid1_or_mid2)
Nand(a = not_mid3, b = not_mid4, out = mid3_or_mid4)
Nand(a = mid1_or_mid2, b = mid1_or_mid2, out = not_mid1_or_mid2);
Nand(a = mid3_or_mid4, b = mid3_or_mid4, out = not_mid3_or_mid4);
Nand(a = not_mid1_or_mid2, b = not_mid3_or_mid4, out = out);
}
Upvotes: 0