题解 | #移位运算与乘法#
移位运算与乘法
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]r_cnt;
reg [7:0]r_out;
always@(posedge clk, negedge rst)begin
if(!rst)
r_cnt <= 0;
else if(r_cnt == 2'd3)
r_cnt <= 2'd0;
else
r_cnt <= r_cnt + 1;
end
always@(posedge clk, negedge rst)begin
if(!rst)
input_grant <= 0;
else
case(r_cnt)
2'd0:input_grant <= 1'b1;
2'd1:input_grant <= 1'b0;
2'd2:input_grant <= 1'b0;
2'd3:input_grant <= 1'b0;
endcase
end
always@(posedge clk, negedge rst)begin
if(!rst)
r_out <= 0;
else if(r_cnt == 0)
r_out = d;
else
r_out = r_out;
end
always@(posedge clk, negedge rst)begin
if(!rst)
out <= 0;
else
case(r_cnt)
2'd0:out <= r_out;
2'd1:out <= (r_out<<2) - r_out;
2'd2:out <= (r_out<<3) - r_out;
2'd3:out <= r_out<<3;
default: out <= 11'd0;
endcase
end
//*************code***********//
endmodule
安克创新 Anker公司福利 816人发布
