sv 之 数组操作 *.min() *.max()
module test;
int array[$];//动态数组
int fifo[$];
int tq[$];
int rand_byte;
int fifo_size;
parameter clk_period =500;
reg clk ;
initial begin
clk =0;
#100ns;
forever begin
#(clk_period/2) clk=~clk;
end
end
intial begin
repeat(10) @(posedge clk) begin
rand_byte=$urandom_range(0,8'hff);
$display("rand_byte = %0h",rand_byte);
fifo.push_back(rand_byte);
end
@(posedge clk);
fifo_size=fifo.size();
for(int i=0; i<fifo_size; i++)begin
array[i]=fifo.pop_front;
$display("array[%0d] = %0h",i,array[i])
end
tq=array.min();
$display(tq);
$display(array.min is %0h",tq[0]);
tq=array.max();
$display(tq);
$display(array.max is %0h",tq[0]);
end
结果打印:
rand_byte = aa
rand_byte = 10
rand_byte = 19
rand_byte = 88
rand_byte = 2f
rand_byte = 44
rand_byte = 1
rand_byte = b3
rand_byte = 1b
rand_byte = dc
array[0] = aa
array[1] = 10
array[2] = 19
array[3] = 88
array[4] = 2f
array[5] = 44
array[6] = 1
array[7] = b3
array[8] = ab
array[9] = dc
'{1}
array.min is 1
'{220}
array.max is dc