Verilog有点难顶,用always块完成,要是用java的话,将一百个数放在一个数组里面,排序就行了
下面代码中的data是一个数,应该是给一百次data才行,不知道要怎么给这个data
用out1和out2作为中间变量存储结果,用cnt进行计数,100次的时候更新max1,max2
module top(
input clk,rst,
input [7:0] data,
output reg [7:0] max1,
output reg [7:0] max2
);
reg [6:0] cnt;
reg [7:0] out1;
reg [7:0] out2;
always@(posedge clk or negedge rst)begin
if(!rst) cnt<=0;
else begin
if(cnt==7’d99) cnt<=0;
else cnt<=cnt+1;
end
end
always@(posedge clk or negedge rst)begin
if(!rst) begin
out1<=0;out2<=0;
end
else begin
if(cnt==0)begin
out1<=data;out2<=data;
end
else begin
if(data>=out1)begin
if(data>=out2)begin
out2<=data;
out1<=out2;
end
else begin
out2<=out2;
out1<=data;
end
end
else begin
out1<=out1;out2<=out2;
end
end
end
end
always@(posedge clk or negedge rst)begin
if(!rst)begin
max1<=0;max2<=0;
end
else begin
if(cnt==0)begin
max1<=out1;
max2<=out2;
end
end
end
endmodule