Prev Problem
Next Problem

59. Absolute Value

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module abs8_func (
    input  signed [7:0] a,
    output       [7:0] abs
);
    function [7:0] abs8;
        input signed [7:0]a;
        begin
        abs8 = (a < 0) ? -a : a;
        if(a==8'h80)
        abs8=8'h80;
        end
    endfunction
    assign abs = abs8(a);
endmodule

 

Was this helpful?
Upvote
Downvote