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

移位运算与乘法

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]r_cnt;
reg [7:0]r_out;
always@(posedge clk, negedge rst)begin
    if(!rst)
        r_cnt <= 0;
    else if(r_cnt == 2'd3)
        r_cnt <= 2'd0;
    else 
        r_cnt <= r_cnt + 1;
        
end

always@(posedge clk, negedge rst)begin
    if(!rst)
        input_grant <= 0;
    else 
        case(r_cnt)
        2'd0:input_grant <= 1'b1;
        2'd1:input_grant <= 1'b0;
        2'd2:input_grant <= 1'b0;
        2'd3:input_grant <= 1'b0;
        endcase
end


always@(posedge clk, negedge rst)begin
    if(!rst)
        r_out <= 0;
    else if(r_cnt == 0)
        r_out = d;
    else 
        r_out = r_out;
end

always@(posedge clk, negedge rst)begin
    if(!rst)
        out <= 0;
    else 
        case(r_cnt)
        2'd0:out <= r_out;
        2'd1:out <= (r_out<<2) - r_out;
        2'd2:out <= (r_out<<3) - r_out;
        2'd3:out <= r_out<<3;
        default: out <= 11'd0;
        endcase
end

  





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

全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
仁者伍敌:实习生要工作经验,工作要实习经验
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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