题解 | #移位运算与乘法#
移位运算与乘法
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
上海得物信息集团有限公司公司福利 1166人发布
查看5道真题和解析