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
// Use the Boolean equation for XOR:   y=(a⋅b')+(a'⋅b)
// + => or
// * => and
// x' => not x
// ============================================================
module xor_gate (
    input  a, b,
    output y
);
    wire not_a;
    wire not_b;
    wire a_and_not_b;
    wire not_a_and_b;

    not_gate nb(.a(b), .y(not_b));
    and_gate a1(.a(a), .b(not_b), .y(a_and_not_b));

    not_gate na(.a(a), .y(not_a));
    and_gate a2(.a(not_a), .b(b), .y(not_a_and_b));

    or_gate o1(.a(a_and_not_b), .b(not_a_and_b), .y(y));

endmodule

 

Was this helpful?
Upvote
Downvote