module sort(clk,reset,int1,
ra,//outout data
a);//input data
//
parameter length=16;// the bits number of data
parameter weikuan=512;// the length of the memory
input clk,reset;
input[length-1:0] a;
output reg int1;
output[length-1:0] ra;
reg[length-1:0] ra;
reg[length-1:0] memo[weikuan-1:0];
integer i,j,m;
initial i=0;
initial j=0;
initial m=0;
//
task exchange;
inout[length-1:0] x,y;
reg[length-1:0] temp;
begin
if(x<y)
begin//exchang 'x' & 'y'
temp=x;
x=y;
y=temp;
end
end
endtask
//***********************************************
always@(posedgeclk or posedge reset)
if(reset)
begin
m=0;
int1=0;
end
else
if(m==weikuan-1)//the memory is full
begin
m=weikuan-1;
if(i==weikuan) //arrangement is over, set int1 to be"1"
begin
i=weikuan;
int1=1;
end
if(i<weikuan)
for(i=0;i<weikuan;i=i+1)//thenput the datas in order
begin
for(j=0;j<weikuan-1-i;j=j+1)//note the range of'j'
exchange(memo[j+1],memo[j]); //if'memo[j+1]<memo[j]', exchange them.
end
end
else//input the data first
begin
memo[m]=a;
m=m+1;
end
endmodule