Start/Exit

Reference Section

_exit
_exit_cleanup
_exit_ok
_on_exit
STACK_1K
STACK_2K
STACK_4K
STACK_8K
STACK_16K
STACK_32K
start

_exit


Descrip
Exits to DOS with a specified ERRORLEVEL.

Syntax
#include <exit.h>
void _exit(int errlevel);

Returns
DOES NOT RETURN (exits to DOS).

Notes
This function sets the DOS ERRORLEVEL to errlevel and terminates the program. This function is in the Spontaneous Assembly startup code, not in the library.

C/C++ Example
	{
	   ...
	   _exit(1);/* error return code */
	}

Inline Assembly Example
	(Not applicable)

Source file START.ASM ASM equiv EXIT_CLEANUP
See also
_exit, _exit

_exit_cleanup


Descrip
Exits to DOS with a specified ERRORLEVEL after executing all functions in the _on_exit list.

Syntax
#include <exit.h>
void _exit_cleanup(int errlevel);

Returns
DOES NOT RETURN (exits to DOS).

Notes
This function executes up to 16 functions which have been added to the _on_exit list. The functions are executed on a last-in, first-out basis. After the cleanup functions have been executed, this function exits to DOS with the errorlevel set equal to errlevel.

WARNING! TSRs should not call this function after going resident. The _tsr_remove or _tsr_hremove function should be called instead.

C/C++ Example
	   ...
	   _exit_cleanup(1);/* exit with ERRORLEVEL = 1 */

Inline Assembly Example
	#include <inline.h>
	   ...
	   mov al,1	/* exit with ERRORLEVEL = 1 */
	   exit_cleanup();    /* call cleanup routines 
	   	  	 	   before exiting */
	   ...

Source file _SEONEXT.ASM ASM equiv EXIT_CLEANUP
See also
_exit, _exit, _on_exit

_exit_ok


Descrip
Exits to DOS with an ERRORLEVEL of zero.

Syntax
#include <exit.h>
void _exit_ok(void);

Returns
DOES NOT RETURN

Notes
This function sets the DOS ERRORLEVEL to zero and terminates the program. This function is in the Spontaneous Assembly startup code, not in the library.

C/C++ Example
	   
	{
	   _exit_ok ();/* exit with no error */
	}

Inline Assembly Example
	(Not applicable)

Source file START.ASM ASM equiv EXIT_OK
See also
_exit, _exit, _on_exit

_on_exit


Descrip
Adds a cleanup function to the list of exit cleanup functions.

Syntax
#include <exit.h>
int _on_exit(void far (near/far *func)(void));

Returns
0 if func was successfully added to the exit list.

-1 if the list is already full.

Notes
This function adds func to a list of functions which are executed before returning to DOS. These functions are executed when any of the following functions are called to return control to DOS: _exit_cleanup, _progid_hremtsr, _progid_remtsr, _tsr_hremove, or _tsr_remove. The functions are executed in last-in, first-out (LIFO) order.

Each call to _on_exit adds another exit function. Up to 16 functions can be added to the _on_exit list. Functions installed with _on_exit must be far functions.

In TINY models, func is a near pointer to allow the program to be converted to a .COM.

Exit cleanup functions should be declared as follows:

void far exit_func(void);

C/C++ Example
	{
	   ...
	   if (_on_exit(clear_scr) == -1)
	   {
	      /* list is full */
	   }
	   ...
	   _exit_cleanup(1);/* call cleanup routine(s), 
	   	  	    exit ERRORLEVEL 1 */
	}

	void far clear_scr()
	{
	   _clr_region();
	}

Inline Assembly Example
	#include <inline.h>
	{
	#if __TINY__
	   mov dx,cs	/* DX = CS */
	#else
	   mov dx,seg clear_scr
	#endif
	   mov ax,offset clear_scr
	   on_exit();
	    jncexit_100/* if successful */
	   ... 	 	/* exit list is full */
	exit_100:
	   ...
	   xor al,al
	   exit_cleanup();    /* call cleanup routine(s), exit */
	   ...
	}

	void far clear_scr()
	{
	   clr_region();
	}

Source file _SEONEXT.ASM ASM equiv ON_EXIT
See also
_exit, _exit

STACK_1K


Descrip
Causes a 1K stack to be linked into the program.

Syntax
STACK_1K

Notes
(Macro) Using this macro causes a 1K stack to be linked into the executable program. The following example causes a 7K stack to be linked into the program:

STACK_1K
STACK_2K
STACK_4K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Source file _SESTK1.ASM ASM equivâ

STACK_2K


Descrip
Causes a 2k stack to be linked into the program.

Syntax
STACK_2K

Notes
(Macro) Using this macro causes a 2K stack to be linked into the executable program. The following example causes a 3K stack to be linked into the program:

STACK_1K
STACK_2K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Source file _SESTK2.ASM ASM equivâ

STACK_4K


Descrip
Causes a 4K stack to be linked into the program.

Syntax
STACK_4K

Notes
(Macro) Using this macro causes a 4K stack to be linked into the executable program. The following example causes a 12K stack to be linked into the program:

STACK_4K
STACK_8K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Source file _SESTK4.ASM ASM equivâ

STACK_8K


Descrip
Causes a 8K stack to be linked into the program.

Syntax
STACK_8K

Notes
(Macro) Using this macro causes an 8K stack to be linked into the executable program. The following example causes a 9K stack to be linked into the program:

STACK_1K
STACK_8K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Source file _SESTK8.ASM ASM equivâ

STACK_16K


Descrip
Causes a 16K stack to be linked into the program.

Syntax
STACK_16K

Notes
(Macro) Using this macro causes a 16K stack to be linked into the executable program. The following example causes a 16K stack to be linked into the program:

STACK_16K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Syntax
_SESTK16.ASM

STACK_32K



Descrip
Causes a 32K stack to be linked into the program.

Syntax
STACK_32K

Notes
(Macro) Using this macro causes a 32K stack to be linked into the executable program. The following example causes a 36K stack to be linked into the program:

STACK_4K
STACK_32K

In the TINY memory model, no stack space is linked into the program.

When using the STACK_1K, STACK_2K, STACK_4K, STACK_8K, STACK_16K, and STACK_32K macros, one of the SA header files (other than those that make code/data transient, or EMS-relocatable) must be included.

Source file _SESTK32.ASM ASM equivâ

start


Descrip
Accepts control from DOS, passes control to main, and returns control to DOS when main terminates.

Syntax
None

Returns
None (see Notes)

Notes
This function contains very compact startup code that can be used in place of the compiler's default startup code when the Spontaneous Assembly library is used instead of the compiler's library. This startup code establishes the segment ordering scheme, initializes the global _psp variable, normalizes the stack, and calls main. If main returns a value via a return statement, the DOS ERRORLEVEL is set to that value as the program terminates.

After finishing its work, main may terminate the program by returning normally or by passing control to an exit function directly.

start is not included in any of the libraries. Instead, it must be linked in manually by listing the name of the appropriate .OBJ file on the LINK command line. For example:

link starts.obj+main.obj, progname.exe, progname.map, sas.lib

start must be the first .OBJ file linked. This allows it to set up the starting program address in the TINY model and to establish the segment ordering scheme. The start object files follow a naming convention of _START?.OBJ, _NSTART?.OBJ, _TSTART?.OBJ, and _DSTARTT.OBJ, where ? is T, S, M, C or L to denote TINY, SMALL, MEDIUM, COMPACT or LARGE.

See the Start/Exit technical notes for more information on using the Spontaneous Assembly startup code instead of compiler startup code.

Source file START.ASM ASM equivâ