/*******************************************************************************
Copyright(c) 2000 - 2006 Analog Devices. All Rights Reserved.

By using this module you agree to the terms of the Analog Devices License
Agreement for DSP Software. 

********************************************************************************
Module name:  boundary.asm
Label name: __boundary


Description:   For a detailed description, please refer to the file "readme.txt".
               which is included in the main project.
*******************************************************************************/

.section        L1_code;
.global      __boundary;
.align                8;   
    
__boundary:
    L1 = 0;
    P2 = R0;                // Address of input array
    P0 = R1;                // No. of ROWS
    P1 = R2;                // N0. of Columns
    R3 = R1 - R1(NS) || R0 = [SP+12];
    I1 = R0;
                       // Clear R3 
    R2 = 1;                        
    
    
    LSETUP(ROW_ST,ROW_END)LC0 = P0;
                            // Loop counter == ROWS 
    P0 = [SP+16]; 
	MNOP || R0 = B[P2++](Z);// fetch first input    
    MNOP;                   // To remove IAU empty stall

ROW_ST:
        LSETUP(COL_ST,COL_END)LC1 = P1;
                            // Loop counter == COLS 
COL_ST:     B[P0] = R0;     // store the input value
            CC = R0 == 0;   // check if input==0
            R0 = B[P2++](Z);// fetch next input
            IF CC JUMP COL_END;
                            // If true jump COL_END
            [I1++] = R3 ||  R1 = B[P0++](z);
                            // Store XY co-ordinate and increment the pointer
COL_END:    R3.L = R3.L + R2.L(NS);
                            // Increment Y co-ordinate 
        R3.L = 0;           // Clear Y co-ordinate
ROW_END:R3.H = R3.H + R2.L(NS);
                            // Increment X co-ordinate 
    RTS;
    NOP;                    // To avoid one stall if LINK or UNLINK happens to 
                            // be the  next instruction in the memory.
                            
__boundary.end:                            
