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

移位运算与乘法

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;
reg [ 7:0] d_q;
always @(posedge clk, negedge rst) begin
    if (rst == 1'h0)
        cnt <= 1'h0;
    else if (cnt == 'd3)
        cnt <= 1'h0;
    else 
        cnt <= cnt + 1'h1;
end

always @(posedge clk, negedge rst) begin
    if (rst == 1'h0)
        d_q <= 1'h0;
    else if (cnt == 'd0)
        d_q <= d;
    else 
        ;
end

always @(posedge clk, negedge rst) begin
    if (rst == 1'h0)
        input_grant <= 1'h0;
    else if (cnt == 'd0)
        input_grant <= 1'h1;
    else 
        input_grant <= 1'h0;
end



always @(posedge clk, negedge rst) begin
    if (rst == 1'h0)
        out <= 1'h0;
    else begin
        case (cnt)
            'd0: out <= d;
            'd1: out <= 3 * d_q;
            'd2: out <= 7 * d_q;
            'd3: out <= 8 * d_q;
            default: out <= out;
        endcase
    end
end

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-29 08:32
点赞 评论 收藏
分享
有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务