Vector2

2023. 6. 8. 23:57FPGA/HDLBits

728x90

Problem Statement

A 32-bit vector can be viewed as containing 4 bytes (bits [31:24], [23:16], etc.). Build a circuit that will reverse the byte ordering of the 4-byte word.

AaaaaaaaBbbbbbbbCcccccccDddddddd => DdddddddCcccccccBbbbbbbbAaaaaaaa

This operation is often used when the endianness of a piece of data needs to be swapped, for example between little-endian x86 systems and the big-endian formats used in many Internet protocols.

 

module top_module( 
    input [31:0] in,
    output [31:0] out );//

    // assign out[31:24] = ...;
    
    assign out [7:0] = in [31:24];
    assign out [15:8] = in [23:16];
    assign out [23:16] = in [15:8];
    assign out [31:24] = in [7:0];

endmodule

'FPGA > HDLBits' 카테고리의 다른 글

Gates4  (0) 2023.06.09
Vectorgates  (0) 2023.06.09
Vector1  (0) 2023.06.08
Vector0  (0) 2023.06.08
7458  (0) 2023.06.08