题目:一个模块,input有clk,rstn,10bit随机数,output为曾经出现过的次大值以及次大值出现的次数。
design:
module comp_secmax(
input clk,
input rstn,
input [9:0]data,
output reg [9:0] sec_max,
output reg [9:0] cnt_sec_max);
reg [9:0] data_in;
reg [9:0] max;
reg [9:0] cnt_max;
always @(posedge clk or negedge rstn)begin
if(!rstn)
data_in<=10'd0;
else
data_in<=data;
end
always @(posedge clk or negedge rstn)begin
if(!rstn)
max<=10'd0;
else if(data_in>max)
max<=data_in;
end
always @(posedge clk or negedge rstn)begin
if(!rstn)
cnt_max<=10'd0;
else if(data_in>max)
cnt_max<=10'd1;
else if(data_in==max)
cnt_max<=cnt_max+1;
end
always @(posedge clk or negedge rstn)begin
if(!rstn)
sec_max<=10'd0;
else if(data_in>max)
sec_max<=max;
else if(data_in==max)
sec_max<=sec_max;
else i