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

移位运算与乘法

http://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// integer i = 1 ; reg [7:0] d_buff = 8'd0 ; always @(posedge clk or negedge rst ) begin if(~rst) begin i <= 1 ; d_buff <= d ; input_grant <= 0 ; out <= 11'd0 ; end else begin case(i) 1:begin i <= 2 ; out <= d ; d_buff <= d ; input_grant <= 1 ; end 2:begin i <= 3 ; out <= (d_buff<<2)-d_buff ; input_grant <= 0 ; end 3:begin i <= 4 ; out <= (d_buff<<3)-d_buff ; input_grant <= 0 ; end 4:begin i <= 1 ; out <= d_buff<<3 ; d_buff <= d ; input_grant <= 0 ; end endcase end end

//**code// endmodule

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务