Prev Problem
Next Problem

69. Binary Subtractor

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module sub4_2c (
    input  [3:0] a,
    input  [3:0] b,
    output [3:0] diff,
    output       bout
);

    wire [4:0] result;

    // Extend operands to preserve carry-out
    assign result = {1'b0, a} + {1'b0, ~b} + 5'b00001;

    assign diff = result[3:0];

    // borrow = NOT carry-out
    assign bout = ~result[4];

endmodule

 

Was this helpful?
Upvote
Downvote