题解 | #使用函数实现数据大小端转换#
使用函数实现数据大小端转换
http://www.nowcoder.com/practice/74c0c19ad0c444959c436a049647a93c
`timescale 1ns/1ns
module function_mod(
input clk,
input rst_n,
input [3:0]a,
input [3:0]b,
output [3:0]c,
output [3:0]d
);
function [3:0] rev;
input [3:0] x;
reg [3:0] rev;
begin
rev[0] = x[3];
rev[1] = x[2];
rev[2] = x[1];
rev[3] = x[0];
end
endfunction
assign c = rst_n ? rev(a) : 4'b0;
assign d = rst_n ? rev(b) : 4'b0;
endmodule