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?

 

The XOR gate is implemented by inverting both inputs, building the terms (a AND NOT b) and (b AND NOT a) using AND gates, and then combining these terms with an OR gate to produce the final XOR result.

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);
    // write code here for or gate
    assign y = a|b;
endmodule

module not_gate(input a, output y);
    // write code here for not gate
    assign y = !a;
endmodule

// ============================================================
// XOR Gate
// ============================================================
module xor_gate (
    input  a, b,
    output y
);
    // TODO: declare intermediate wires
    wire not_a;
    wire not_b;
    wire and_a_notb;
    wire and_b_nota;

    // TODO: instantiate required gates
    not_gate not_gate_a (a,not_a);
    not_gate not_gate_b (b,not_b);

    and_gate and_a_not_b (a, not_b, and_a_notb);
    and_gate and_b_not_a (b, not_a, and_b_nota);

    or_gate xor_out (and_b_nota,and_a_notb,y);

endmodule

 

Was this helpful?
Upvote
Downvote