UART receive buffer writing and reading
On UART receive event:

    FIFO[Wr_pointer]= UART_Char;
    WR_Pointer++;
    WR_Pointer &amp; = 3FF;// FIFO[1024] roll over 1022..1023...0...1...2
    if WR_Pointer==RD_Pointer then
        Overrun= true;
    else
    {
        SizeFIFO = (WR_Pointer - RD_Pointer);
        SizeFIFO &amp; = 3FF;
    }


Circular buffer example. There is no need to copy data from FIFO to another location since the data are just overwritten.

In the application:

SizeFIFO_temp = SizeFIFO; //you don't want a bug when ISR will insert new data while processing the buffer
for i=0 to SizeFIFO_temp  do
{
   Data[i]=FIFO[RD_Pointer]; //it's all up to you how you process the FIFO's data
   RD_Pointer++;
   RD_Pointer &amp;= 3FF; 
}
SizeFIFO = (WR_Pointer - RD_Pointer);
SizeFIFO &amp; = 3FF;