Prev Problem
Next Problem

57. Using Functions

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module parity_and_reverse(
    input  wire [7:0] a,
    output wire       parity,
    output wire [7:0] rev
);

    // ============================
    // Pre-defined Function: parity8
    // ============================
    function parity8(input [7:0] x);
        integer i;
        begin
            parity8 = 0;
            for (i = 0; i < 8; i = i + 1)
                parity8 = parity8 ^ x[i];
        end
    endfunction

    // ==============================
    // Pre-defined Function: reverse8
    // ==============================
    function [7:0] reverse8(input [7:0] x);
        integer i;
        begin
            for (i = 0; i < 8; i = i + 1)
                reverse8[i] = x[7 - i];
        end
    endfunction

    // ============================
    // Module Output Assignments
    // ============================
    assign parity = parity8(a);
    assign rev    = reverse8(a);

endmodule

 

Was this helpful?
Upvote
Downvote