home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / ASMLIB40.ZIP / TC&ASM.DOC < prev    next >
Encoding:
Text File  |  1995-02-27  |  3.1 KB  |  77 lines

  1.  
  2. CALLING ASMLIB FROM C PROGRAMS
  3.  
  4. I have used many ASMLIB subroutines with Turbo C and Borland C++.  The
  5. following comments and helpful hints apply to both compilers even if I
  6. only mention Turbo C.
  7.  
  8. You can call most ASMLIB subroutines from Turbo C if you follow these
  9. simple rules:
  10.  
  11. ■)  Tell your C program that the ASMLIB subroutine is a PASCAL function
  12.     This makes the C compiler convert the subroutine name to upper case
  13.     and supresses the _leading _underscore in the subroutine name.  It's
  14.     good practice to declare the subroutine in UPPER CASE in the event of
  15.     name conflicts (such as STRLEN).
  16.  
  17.     /*  Example:  */
  18.     extern  void pascal TPRINT(void);
  19.  
  20.  
  21. ■)  Load the 80x86 registers before calling the ASMLIB subroutine.  Be
  22.     sure to save the DI and SI registers because Turbo C expects that
  23.     these registers will not change across subroutien calls.
  24.  
  25.     /*  Example:  */
  26.  
  27.     asm  push si;          /* TC wants SI to be saved */
  28.     _DX = 0;               /* upper left corner of screen */
  29.     _AH = 15;              /* bright white */
  30.     _SI = msg;             /* pointer to ASCIIZ string */
  31.     tprint();
  32.     asm  pop  si;          /* restore SI register */
  33.  
  34.  
  35. ■)  ASMLIB subroutines using the 8087 will use Turbo C's emulation
  36.     library if re-assembled with the /E option (except TINY model).
  37.  
  38.  
  39. ■)  values in registers returned by ASMLIB subroutines should be used
  40.     or saved immediately; C code executed after calling an ASMLIB
  41.     subroutine may change any of the registers.
  42.  
  43.  
  44. ■)  When compiling from within the Turbo C editor, include ASM86M.LIB
  45.     in your .PRJ file (ASM86S.LIB for small model, ASM86H.LIB for
  46.     huge model).
  47.  
  48.  
  49. ■)  ASMLIB's HUGE model library does not strictly adhere to Turbo C's HUGE
  50.     model assumptions.  Many ASMLIB HUGE model subroutines assume DS:DGROUP,
  51.     while the standard HUGE model assumes DS:nothing.  (ASMLIB also does
  52.     not provide a LARGE model library; the ASMLIB MEDIUM model libraries
  53.     may be used instead, with the same treatment of DS).
  54.  
  55.     /*  Example:                                            */
  56.     /*  use ASMLIB's DRAWLINE subroutine; assumes DS:DGROUP */
  57.  
  58.     extern void pascal DRAWLINE(void);
  59.  
  60.     asm  push ds;           /* save DS segment - this may not be nessesary */
  61.     asm  mov  ax,ss;        /* get DROUP segment                           */
  62.     asm  mov  ds,ax;        /* DS = DGROUP                                 */
  63.     _BX=&x0;                /* point to line endpoint data IN LOCAL MEMORY */
  64.     DRAWLINE();
  65.     asm  pop  ds;           /* restore DS segment if pushed                */
  66.  
  67.  
  68. ■)  Many ASMLIB subroutines use the ASMLIB near heap during execution.
  69.     Subroutines in ASMLIB's H2MALLOC.ASM intercept ASMLIB subroutines'
  70.     calls to ASMLIB near heap functions and use the C compiler's
  71.     malloc, free and realloc library functions instad of ASMLIB's heap.
  72.     H2MALLOC must be assembled with the TASM or MASM /mx switch, and H2MALLOC
  73.     must be specified must be specified in your list of object modules.
  74.     MS-LINK also wants you to use the /NOE command-line switch.
  75.     
  76.  
  77.