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 not_a, not_b;
    wire and_1, and_2;

    not_gate ng_a (
        .a(a), 
        .y(not_a)
    );
    not_gate ng_b (
        .a(b), 
        .y(not_b)
    );

    and_gate ag_1 (
        .a(a), 
        .b(not_b), 
        .y(and_1)
    );
    and_gate ag_2 (
        .a(b), 
        .b(not_a), 
        .y(and_2)
    );

    or_gate og (
        .a(and_1), 
        .b(and_2), 
        .y(y)
    );

endmodule

 

Was this helpful?
Upvote
Downvote