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

/*Write your code here*/

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

    // Perform A + (~B) + 1 using 5-bit addition
    assign {cout, diff} = {1'b0, a} + {1'b0, ~b} + 5'b00001;

    // Borrow occurs when A < B → bout = ~cout
    assign bout = ~cout;
endmodule

 

Was this helpful?
Upvote
Downvote