Prev Problem
Next Problem

69. Binary Subtractor

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

simply bout is the not of carry generated

Code

/*Write your code here*/
module sub4_2c(
    input [3:0] a,b,
    output [3:0] diff,
    output bout
);
    assign diff = a + ~b +4'd1;
    assign bout = (a[3]<b[3]) | (a[3]==b[3] && (a[2]<b[2])) | ((a[3]==b[3] && a[2]==b[2]) && (a[1]<b[1])) | ((a[3]==b[3] && a[2]==b[2] && a[1]==b[1]) && a[0]<b[0]);
endmodule

// simpler way, borrow is the not of carry generated during the sum
// wire c;
// assign {c,diff} = a + ~b + 4'd1;
// assign bout = ~c;

 

Was this helpful?
Upvote
Downvote