题解 | #位拆分与运算#

位拆分与运算

https://www.nowcoder.com/practice/1649582a755a4fabb9763d07e62a9752

`timescale 1ns/1ns

module data_cal(
input clk,
input rst,
input [15:0]d,
input [1:0]sel,

output reg [4:0]out,
output reg validout
);
//*************code***********//

reg [15:0]temp;

always@(posedge clk or negedge rst)
if(!rst)
    begin out<=5'd0; validout<=1'b0;end
else
case(sel)
2'd0: begin temp<=d; out<=5'd0; validout<=1'b0;end
2'd1: begin out<=temp[3:0]+temp[7:4]; validout<=1'b1;end
2'd2: begin out<=temp[3:0]+temp[11:8]; validout<=1'b1;end
2'd3: begin out<=temp[3:0]+temp[15:12]; validout<=1'b1;end
default:begin out<=5'd0; validout<=1'b0;end
endcase


//*************code***********//
endmodule

注意题干:只有sel=0输入有效

全部评论

相关推荐

05-19 19:57
蚌埠学院 Python
2237:Gpa70不算高,建议只写排名,个人技能不在多而在精,缩到8条以内。项目留一个含金量高的,减少间距弄到一页,硕士简历也就一页,本科不要写很多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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