写一个verilog代码,要求从两组数中找到两个最大值,每组10000个数值。
时间: 2024-05-27 18:13:43 浏览: 91
用verilog实现求最大公约数
5星 · 资源好评率100%
Sure, I can answer your question. Here's a Verilog code that finds the two maximum values from two sets of 10,000 numbers:
module find_max(
input [9999:0] set1,
input [9999:0] set2,
output reg [31:0] max1,
output reg [31:0] max2
);
reg [31:0] max_val1;
reg [31:0] max_val2;
integer i;
initial begin
max_val1 = 0;
max_val2 = 0;
for(i=0; i<10000; i=i+1) begin
if(set1[i] > max_val1) begin
max_val2 = max_val1;
max_val1 = set1[i];
end else if(set1[i] > max_val2) begin
max_val2 = set1[i];
end
end
for(i=0; i<10000; i=i+1) begin
if(set2[i] > max_val1) begin
max_val2 = max_val1;
max_val1 = set2[i];
end else if(set2[i] > max_val2) begin
max_val2 = set2[i];
end
end
max1 = max_val1;
max2 = max_val2;
end
endmodule
I hope that helps! Let me know if you have any further questions.
阅读全文