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
module and_gate(input a, input b, output y);
    assign y = a & b;
    endmodule

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

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

            // XOR Gate using basic gates
            module xor_gate(input a, input b, output y);
                wire n_a, n_b;
                    wire and1_out, and2_out;

                        not_gate not_a(.a(a), .y(n_a));
                            not_gate not_b(.a(b), .y(n_b));

                                and_gate and1(.a(a), .b(n_b), .y(and1_out));
                                    and_gate and2(.a(n_a), .b(b), .y(and2_out));

                                        or_gate or1(.a(and1_out), .b(and2_out), .y(y));
                                        endmodule

 

Was this helpful?
Upvote
Downvote