/*******************************************************************************
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: open.asm
Label name: __open


Description:   For a detailed description, please refer to the file "readme.txt".
               which is included in the main project.

*******************************************************************************/
.section   L1_code;
.global    __open;
.align     8;
.extern __dilation;
.extern __erosion;
    
__open:
    [--SP]=(R7:4,P5:3);
                            // Push R7:4 and P5:3 
    R3=R1.L *R2.L(IS)||P5=[SP+40];
                            // Get row*col and address of structured element 
    P3=R3;                  // get offset to decrement stack.
    R7=R1;                  // No. of rows
    R6=R2<<0|| P4=[SP+44];  // Address of output array
    [--SP]=RETS;            // store return address
    SP-=P3;                 // decrement stack pointer to store temp. result
    R4=SP;                       
    SP+=-20;                // decrement stack pointer to pass arguments
    [SP+12]=P5;             // arguments to erosion function
    [SP+16]=R4;
    CALL __erosion;
    R0=R4;                  // Arguments to dilation function
    R1=R7<<0;				//Changed from 535 to 533
    [SP+12]=P5;
    R2=R6<<0;
    [SP+16]=P4;        		//Changed from 535 to 533
    CALL __dilation;
    SP+=20;                 // Increment the stack pointer to proper position
    SP=SP+P3;
    RETS=[SP++];            // pop RETS reg.
    (R7:4,P5:3)=[SP++];     // Pop R7:4 and P5:3
    RTS;    
    NOP;                    // To avoid one stall if LINK or UNLINK happens to 
                            // be the  next instruction in the memory.
__open.end:                            
