Prev Problem
Next Problem

39. Half Adder using NAND Primitive

module ha_nand_only(
  input  wire a,
  input  wire b,
  output wire sum,
  output wire cout
);
  wire n1, n2, n3;
  nand g0(n1, a, b);
  nand g1(n2, a, n1);
  nand g2(n3, b, n1);
  nand g3(sum, n2, n3);
  nand g4(cout, n1, n1);
endmodule

πŸ’‘ Remember

  • Inverter: ~x via nand(x,x). AND: x&y via nand(x,y) then invert with another nand.
  • XOR with 4 NANDs: n1=~(a&b), n2=~(a&n1), n3=~(b&n1), sum=~(n2&n3).
  • Structural designs with primitives are combinational; every output is a pure function of inputs.