Prev Problem
Next Problem

9. XOR Gate Using Basic Gates

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

// ============================================================
// Basic Gates (given)
// ============================================================
module and_gate(input a, b, output y);
    assign y = a & b;
endmodule

module or_gate(input a, b, output y);
    assign y=a|b;

endmodule

module not_gate(input a, output y);
    assign y=~a;

endmodule

// ============================================================
// XOR Gate
// ============================================================
module xor_gate (
    input  a, b,
    output y
);
    wire and1;
    wire and2;
    wire na;
    wire nb;

    not_gate n11(.a(a), .y(na));
    not_gate n22(.a(b), .y(nb));

    and_gate a11(.a(a), .b(nb), .y(and1));
    and_gate a22(.a(na), .b(b), .y(and2));

    or_gate o11(.a(and1), .b(and2), .y(y));



endmodule

 

Was this helpful?
Upvote
Downvote