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

移位运算与乘法

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 [7:0] d_dly;
reg [3:0] cnt;
wire      rst_dly_catch;
reg       rst_dly;
assign rst_dly_catch = ~rst_dly & rst;    //抓取复位上升沿,拉高初始的input_grant。
always @(posedge clk or negedge rst)begin 
    if(!rst)begin
        d_dly <= 8'd0;
        rst_dly <= 1'b0;
      end
    else begin
        d_dly <= d;
        rst_dly <= rst;
    end
end
always @(posedge clk or negedge rst)begin //计数0->1,1->3,2->7,3->8
    if(!rst)
        cnt <= 4'd0;
    else if(cnt >= 4'd3)
        cnt <= 4'd0;
    else
        cnt <= cnt + 4'd1;
end
always @(posedge clk or negedge rst) begin  //输出out
    if(!rst)
        out <= 11'd0;
    else begin
     case(cnt)
        4'd0:out <= d;
        4'd1:out <= 3 * out;
        4'd2:out <= 7 * (out/3);
        4'd3:out <= 8 * (out/7);
        default:  ;
        endcase
    end
end
always @(posedge clk or negedge rst)begin //inpu_grant输出控制
    if(!rst)
        input_grant <= 1'b0;
    else if (rst_dly_catch == 1'b1)
        input_grant <= 1'b1;
    else if(cnt == 4'd0) 
        input_grant <= 1'b1;
    else
        input_grant <= 1'b0;
end
//*************code***********//
endmodule

全部评论

相关推荐

风中翠竹:真的真的真的没有kpi。。。面试官是没有任何kpi的,捞是真的想试试看这个行不行,碰碰运气,或者是面试官比较闲现在,没事捞个人看看。kpi算HR那边,但是只有你入职了,kpi才作数,面试是没有的。
双非有机会进大厂吗
点赞 评论 收藏
分享
苍蓝星上艾露:这简历。。。可以试试我写的开源简历优化工具https://github.com/weicanie/prisma-ai
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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