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

移位运算与乘法

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] x;
reg [7:0] din;

always@(posedge clk or negedge rst)
if(!rst)
        x<=0;
else 
    x<= (x==2'd3) ? 1'd0:x+1'd1;

always@(posedge clk or negedge rst)
if(!rst)
    begin
        out<=11'd0;
        input_grant<=1'b0;
    end
else
    case(x)
        2'd0:begin din<=d;out<=d;input_grant<=1'b1; end
        2'd1:begin out<=(din<<2)-din;input_grant<=1'b0; end
        2'd2:begin out<=(din<<3)-din;input_grant<=1'b0; end
        2'd3:begin out<=din<<3;input_grant<=1'b0; end
    endcase
//*************code***********//
endmodule

全部评论

相关推荐

用微笑面对困难:你出于礼貌叫了人一声大姐,大姐很欣慰,她真把你当老弟
点赞 评论 收藏
分享
在做测评的伊登很想奋...:别看了,简历没问题,中国人才太多了,所以显得没什么光辉,别怀疑,这水平进不去,那证明企业里边全是985。除了多投碰运气也没啥办法。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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