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

移位运算与乘法

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] mid_d;
reg [1:0] cyc;
always @(posedge clk or negedge rst)begin
    if (rst == 0)begin
        mid_d <= 0;
        cyc <= 0;
        input_grant <= 0;
    end
    else 
        if(cyc == 0)begin
            cyc <= cyc+1;
            mid_d <= d;
            input_grant <= 1;
        end
        else begin
            cyc <= cyc+1;
            input_grant <= 0;
        end
end

always @(posedge clk or negedge rst)begin
    if (rst == 0)
        out <= 0;
    else 
        case(cyc)
        2'b00: out <= d;
        2'b01: out <= mid_d*3;
        2'b10: out <= mid_d*7;
        2'b11: out <= mid_d*8;
        endcase
end



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

全部评论

相关推荐

07-30 11:27
门头沟学院 Java
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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