home *** CD-ROM | disk | FTP | other *** search
-
- CALLING ASMLIB FROM C PROGRAMS
-
- I have used many ASMLIB subroutines with Turbo C and Borland C++. The
- following comments and helpful hints apply to both compilers even if I
- only mention Turbo C.
-
- You can call most ASMLIB subroutines from Turbo C if you follow these
- simple rules:
-
- ■) Tell your C program that the ASMLIB subroutine is a PASCAL function
- This makes the C compiler convert the subroutine name to upper case
- and supresses the _leading _underscore in the subroutine name. It's
- good practice to declare the subroutine in UPPER CASE in the event of
- name conflicts (such as STRLEN).
-
- /* Example: */
- extern void pascal TPRINT(void);
-
-
- ■) Load the 80x86 registers before calling the ASMLIB subroutine. Be
- sure to save the DI and SI registers because Turbo C expects that
- these registers will not change across subroutien calls.
-
- /* Example: */
-
- asm push si; /* TC wants SI to be saved */
- _DX = 0; /* upper left corner of screen */
- _AH = 15; /* bright white */
- _SI = msg; /* pointer to ASCIIZ string */
- tprint();
- asm pop si; /* restore SI register */
-
-
- ■) ASMLIB subroutines using the 8087 will use Turbo C's emulation
- library if re-assembled with the /E option (except TINY model).
-
-
- ■) values in registers returned by ASMLIB subroutines should be used
- or saved immediately; C code executed after calling an ASMLIB
- subroutine may change any of the registers.
-
-
- ■) When compiling from within the Turbo C editor, include ASM86M.LIB
- in your .PRJ file (ASM86S.LIB for small model, ASM86H.LIB for
- huge model).
-
-
- ■) ASMLIB's HUGE model library does not strictly adhere to Turbo C's HUGE
- model assumptions. Many ASMLIB HUGE model subroutines assume DS:DGROUP,
- while the standard HUGE model assumes DS:nothing. (ASMLIB also does
- not provide a LARGE model library; the ASMLIB MEDIUM model libraries
- may be used instead, with the same treatment of DS).
-
- /* Example: */
- /* use ASMLIB's DRAWLINE subroutine; assumes DS:DGROUP */
-
- extern void pascal DRAWLINE(void);
-
- asm push ds; /* save DS segment - this may not be nessesary */
- asm mov ax,ss; /* get DROUP segment */
- asm mov ds,ax; /* DS = DGROUP */
- _BX=&x0; /* point to line endpoint data IN LOCAL MEMORY */
- DRAWLINE();
- asm pop ds; /* restore DS segment if pushed */
-
-
- ■) Many ASMLIB subroutines use the ASMLIB near heap during execution.
- Subroutines in ASMLIB's H2MALLOC.ASM intercept ASMLIB subroutines'
- calls to ASMLIB near heap functions and use the C compiler's
- malloc, free and realloc library functions instad of ASMLIB's heap.
- H2MALLOC must be assembled with the TASM or MASM /mx switch, and H2MALLOC
- must be specified must be specified in your list of object modules.
- MS-LINK also wants you to use the /NOE command-line switch.
-
-
-