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  wire signed [7:0] a,
    output wire [7:0] abs
);

    // =====================================
    // User-defined function: abs8
    // DO NOT RENAME
    // =====================================
    function [7:0] abs8(input signed [7:0] x);
        begin
            abs8 = (x < 0) ? -x : x;
        end
    endfunction

    // =====================================
    // Drive output using function
    // =====================================
    assign abs = abs8(a);

endmodule

 

Was this helpful?
Upvote
Downvote