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
);
    // ---------- Write function here----------
    function [7:0] abs8;
        input [7:0] x;
        begin
            // abs8 = (x[7]) ? ~x+7'b1 : x;  // alternative
            abs8 = (x[7]) ? -x : x;
        end
    endfunction



    // Function called here
    assign abs = abs8(a);

endmodule

 

Was this helpful?
Upvote
Downvote