题解 | #移位运算与乘法#
移位运算与乘法
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 [10:0] out1;
reg [10:0] out2;
reg [10:0] out3;
always @(posedge clk or negedge rst)
if (rst == 1'b0)
cnt <= 1'b0;
else if (cnt == 2'b11)
cnt <= 1'b0;
else
cnt <= cnt + 1'b1;
always @(posedge clk or negedge rst)
if (rst == 1'b0)
out <= 11'b0;
else if(cnt == 1'b0)
begin
out <= d;
out1 <= (d <<2) - d;
out2 <= (d <<3) - d;
out3 <= d << 3;
end
else if (cnt == 2'b01)
out <= out1;
else if (cnt == 2'b10)
out <= out2;
else if (cnt == 2'b11)
out <= out3;
always @(posedge clk or negedge rst)
if (rst == 1'b0)
input_grant <= 1'b0;
else if(cnt == 1'b0)
input_grant <= 1'b1;
else
input_grant <= 1'b0;
//*************code***********//
endmodule