Prev Problem
Next Problem

62. Nibble Swap

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

module nibble_swap_task (
    input  [7:0] x,
    output reg [7:0] y
);
    // ---------- Write this task ----------
    task swap_nibbles;
        input  [7:0] xin;
        output [3:0] hi;
        output [3:0] lo;
        begin
            // TODO: assign hi and lo from xin
           hi=xin[7:4]; // hi = ...
           lo=xin[3:0]; // lo = ...
        end
    endtask
    // -------------------------------------

    reg [3:0] hi_n, lo_n;

    always @* begin
      swap_nibbles(x,hi_n,lo_n);
      y={lo_n,hi_n};  // TODO: call the task and build y
    end

endmodule

 

Was this helpful?
Upvote
Downvote