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 approach is to implement the XOR operation using fundamental logic gates: first generate the complemented inputs, then form the two essential product terms, and finally combine them with an OR gate to obtain the exclusive-OR output.

 

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 a2, b2, y1, y2;
    // TODO: instantiate required gates
    not_gate not1 (.a(a), .y(a2));
    not_gate not2 (.a(b), .y(b2));
    and_gate and1 (.a(a), .b(b2), .y(y1));
    and_gate and2 (.a(a2), .b(b), .y(y2));
    or_gate or1 (.a(y1), .b(y2), .y(y));


endmodule

 

Was this helpful?
Upvote
Downvote