题解 | #移位运算与乘法#

移位运算与乘法

https://www.nowcoder.com/practice/1dd22852bcac42ce8f781737f84a3272

`timescale 1ns/1ns
module multi_sel(
input [7:0]d ,
input clk,
input rst,
output reg input_grant,
output reg [10:0]out
);
//*************code***********//
reg [1:0] cnt;
wire [7:0] d_r;
assign d_r = (cnt == 2'd0) ? d : d_r;

always@(posedge clk or negedge rst) begin
    if(!rst)
        cnt <= 2'b0;
    // else if(cnt == 2'd3)
    //     cnt <= 2'b0;
    else cnt <= cnt + 1'b1;
end

always@(posedge clk or negedge rst) begin
    if(!rst)
        out <= 11'b0;
    else if(cnt == 2'd0)
        out <= d_r;
    else if(cnt == 2'd1)
        out <= (d_r<<2)-d_r;
    else if(cnt == 2'd2)
        out <= (d_r<<3)-d_r;    
    else if(cnt == 2'd3)
        out <= (d_r<<3);
end

always@(posedge clk or negedge rst) begin
    if(!rst)
        input_grant <= 1'b0;
    else if(cnt == 2'd0)
        input_grant <= 1'b1;
    else input_grant <= 1'b0;
end
//*************code***********//
endmodule

全部评论

相关推荐

purcoter:虚拟货币预测正确率百分之99,还要找工作干嘛,不早就财富自由了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务