题解 | #移位运算与乘法#
移位运算与乘法
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