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 n_a, n_b, and1, and2;

not_gate n1 (.a(a), .y(n_a));
not_gate n2 (.a(b), .y(n_b));

and_gate andgt1 (.a(a), .b(n_b), .y(and1));
and_gate andgt2 (.a(n_a), .b(b), .y(and2));

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

endmodule

 

Was this helpful?
Upvote
Downvote