image.png
image.png
輸入描述:
輸入信號 d, clk, rst
類型 wire
在testbench中,clk為周期5ns的時鐘,rst為低電平復位
輸出描述:
輸出信號 input_grant out
類型 reg
這里有一點需要了解下:就是>>1 相當于乘2,那么就是乘3的話就是相當于>>2-1[即乘4-1]
image.png
實現代碼:
`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] din;
always@(posedge clk or negedge rst) begin
if(!rst) begin
cnt <= 0;
out <= 0;
input_grant <= 0;
din <= 0;
end
else begin
cnt <= cnt +1;
case(cnt)
0: begin
din <= d;
input_grant <= 1;
out <= d;
end
1: begin
input_grant <= 0;
out <= (din<<2) -din;
end
2: begin
input_grant <= 0;
out <= (din<<3)-din;
end
3: begin
input_grant <= 0;
out <= (din<<3);
end
endcase
end
end
endmodule