11.14 Functions built into the compiler

----------------------------------------

For certain functions there is no source code in the compiler

libraries. The compiler generates the code for these functions:

ABORT Aborts process (abnormal termination)

atan Calculates arctg numbers

atan2 Calculates arctg numbers

ATEXIT Registers a function to be called at normal program termination

cos Returns cosine of angle

EXIT Exits program with error code (normal process termination)

exp Computes the exponential function

inp/inportb Reads one byte from port

inport Reads word from port

inportd Reads double word from port

fabs Returns absolute value of number

log Calculates natural logarithm of number

log10 Calculates decimal logarithm of number

outp/outportb Writes one byte to port

outport Writes word to port

outportd Writes double word to port

sin Returns sine of angle

sqrt Extracts square root via the FPU.

tan Returns tangent of angle

These functions have been built into the compiler because at present it

can thus generate more efficient code than if they were in the libraries.

In the future, as the compiler is further developed, these functions will

gradually be exported from the compiler to the libraries.

But there is nothing to keep you from writing your own library

functions of the same name. When it encounters such a function, the

compiler will not give any report but will simply use your function of this

name.

11.14.1 'ABORT', 'ATEXIT', 'EXIT' built-in functions

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The functions 'ABORT' and 'EXIT' are related to the operation of the

directive '#atexit' and the function 'ATEXIT'. Only the compiler can best

execute and mutually integrate them, and they are therefore built into

the compiler.

'ATEXIT' is a register function which registers a function whose

address is transferred as a parameter, i. e., via (E)AX, as a function

which terminates the program. Successful registration of 'ATEXIT' returns

the value 0. Up to 16 functions can be registered.

Terminating functions must not have parameters and a return. These

functions are executed in an order the reverse of how they were

registered if the program is terminated by calling 'ABORT' or 'EXIT' or

if the work of 'main' terminates. If the program is terminated by calling

'ExitProcess' under Windows or 'AH=0x4C; $int 0x21' under DOS, it will

exit without starting the registered functions.

If '#atexit' is not switched on, 'ABORT' and 'EXIT' will call

'ExitProcess' under Windows or 'AH=0x4C; $int 0x21' under DOS. 'ABORT' is

not given any parameters and it terminates the program with return code

0. 'EXIT' is given the return code as the parameter with which it

terminates the program.

11.14.2 inp/inportb, inport, inportd, outp/outportb, outport and

outportd builtin functions.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These functions are always inserted into the code as macros, i. e.,

no function call is ever generated for these functions. Depending on the

value of the port with which these functions are working, different code

is generated. This all produces smaller code.

Functions of reading from a port have the following prototype:

byte inp ( word port );

dword inportd ( word port );

dword inportd ( word port );

Functions of writing to a port have the following prototype:

void outp ( byte val; word port );

void outport ( word val; word port );

void outportd ( dword val; word port );

The names 'inp' and 'inportb' are synonyms, as are 'outp' and

'outportb'.

11.14.3 Floating-point built-in functions

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These functions are executed by the compiler and are always inserted

into the code as macros, i. e., no function call is ever generated for

them. Furthermore, if the parameter of one function is a call to another,

the result of operation of the second function remains in the FPU stack

and the first function uses this result directly from the stack. This

gives more compact code. For example:

test.c-- 7: f = sin( sqrt(1) );

0100 D9061C01 fld [11Ch]

0104 D9FA fsqrt

0106 D9FE fsin

0108 D91E2001 fstp [120h]

010C 9B fwait

This type of function has the following prototype:

float atan ( float val );

float atan ( float val, val2 );

float cos ( float val );

float exp ( float val );

float fabs ( float val );

float log ( float val );

float log10 ( float val );

float sin ( float val );

float sqrt ( float val );

float tan ( float val );