题解 | #使用函数实现数据大小端转换#

使用函数实现数据大小端转换

https://www.nowcoder.com/practice/74c0c19ad0c444959c436a049647a93c

1、函数中不能包含任何时间控制语句
2、函数只能用于组合逻辑
3、函数不能调用任务
4、函数中至少有一个输入参数
5、函数中赋值语句寄存器必须是和函数名、位宽相同

代码如下:
`timescale 1ns/1ns
module function_mod(
	input [3:0]a,
	input [3:0]b,
	
	output [3:0]c,
	output [3:0]d
);
assign c = trans(a);
assign d = trans(b);

function [3:0]trans;
	input [3:0]a_in;
begin
	trans[0] = a_in[3];
	trans[1] = a_in[2];
	trans[2] = a_in[1];
	trans[3] = a_in[0];
end
endfunction
endmodule

#自学笔记#
全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:01
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务