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

移位运算与乘法

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 ;
always@(posedge clk or negedge rst) begin 
    if(!rst) begin
        cnt <= 0;
    end
    else
        cnt <= cnt + 1 ;

end

reg [7:0] d_reg ;
always@(posedge clk or negedge rst) begin 
    if(!rst) begin
        input_grant <= 0;
        out  <= 0 ;
        d_reg <= 0 ;
    end
    else if(cnt == 2'd0) begin
        input_grant <= 1;
        out <= d ;
        d_reg <= d ;
    end
    else if(cnt == 2'd1) begin
        input_grant <= 0;
        out <= {d_reg,1'b0}+d_reg ;
    end
    else if(cnt == 2'd2) begin
        input_grant <= 0 ;
        out <= {d_reg,{3{1'b0}}} - d_reg ;
    end
    else if(cnt == 2'd3) begin
        input_grant <= 0;
        out <= {d_reg,{3{1'b0}}};
    end


end




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

全部评论
强强强
点赞 回复 分享
发布于 2023-06-29 20:58 河南

相关推荐

LXXXXd:有点杂,想搞自动化的话没必要把法律的经历写上去
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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