题解 | #位拆分与运算#

位拆分与运算

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 validout
);
//*************code***********//
always@(posedge clk or negedge rst)begin
    if(!rst)
        out <= 5'd0;
    else begin
        case(sel)
            2'd0: 
                begin 
                    out <= 5'd0;
                    d1 <= d; //注意只有在sel=0的时候采集到的输入才有效,也就是说每隔4clk采样一次数据
                end
            2'd1: out <= d1[3:0] + d1[7:4];
            2'd2: out <= d1[3:0] + d1[11:8];
            2'd3: out <= d1[3:0] + d1[15:12];
        endcase
    end
end

assign validout = (sel!=0 && rst==1) ? 1'b1 : 1'b0;

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

全部评论

相关推荐

01-10 22:44
已编辑
门头沟学院 Java
不知道怎么取名字_:其实好多都是这样,好多公司除创业的外,都是有自己的那一套了,新项目也会在基于老项目适配,但是这种要是能把人家项目的代码全部看完,自己整体出架构方案,使用的技术,那就收获很大的
有深度的简历长什么样?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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