home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / MISCTI10.ZIP / TI308.ASC < prev    next >
Encoding:
Text File  |  1988-04-18  |  2.0 KB  |  67 lines

  1. PRODUCT : TURBO PROLOG     NUMBER : 308
  2. VERSION : 1.0xx
  3.      OS : PC-DOS
  4.    DATE : October 9, 1986
  5.  
  6.   TITLE : ASSEMBLER INTERFACE 
  7.  
  8. The following describes how to call a Microsoft Assembler routine 
  9. from Turbo Prolog.
  10.  
  11.  
  12.    global predicates
  13.       double(integer,integer) - (i,o) language asm
  14.  
  15.    goal
  16.       write("Enter an integer"),
  17.       readint(A),nl,
  18.       double(A,B),
  19.       write("Double that value is ",B),
  20.       readchar(_).
  21.  
  22. Write  the following assembler routine (ASMPROG.ASM) and  compile 
  23. to object  code.
  24.  
  25.   A_PROG     SEGMENT  BYTE
  26.              ASSUME CS:A_PROG
  27.   PUBLIC     DOUBLE_0
  28.   DOUBLE_0   PROC   FAR
  29.              PUSH   BP                  ; save old bp     
  30.              MOV    BP,SP               ; set up bp to access
  31. parameters              MOV    AX,[BP]+10          ; move input
  32. parm to AX
  33.              ADD    AX,AX               ; double AX
  34.              LES    DI,DWORD PTR [BP]+6 ; load ES,DI with pointer
  35. to 
  36.                                         ; output parameter 
  37.              MOV    ES:[DI],AX          ; store AX at ES:[DI] 
  38.              POP    BP                  ; restore BP register
  39.              RET 6                      ; return, popping
  40. parameters
  41.                                         ; off the stack.     
  42.              DOUBLE_0 ENDP
  43.              A_PROG   ENDS
  44.              END
  45.  
  46.  
  47. Link  the  Prolog and the Assembler object modules together  with 
  48. the following command:
  49.  
  50.       C> link init+double+asmprog+double.sym,double,,prolog
  51.  
  52. Now, run the program by typing "DOUBLE."
  53.  
  54.  
  55. The  basic rules for interfacing assembler routines to link  with 
  56. Turbo Prolog routines are as follows:
  57.  
  58.      1) Make  sure that all sub-routines are 'PROC FAR',  because                
  59. Turbo Prolog uses FAR calls exclusively.
  60.  
  61.      2) Save  the  BP upon entrance to the Assembler  program, 
  62. and          restore it on exit.
  63.  
  64.      3) On exit,  clear the stack with a RET X,  where X is equal         
  65. to number of bytes used by the parameters. 
  66.  
  67.