home *** CD-ROM | disk | FTP | other *** search
- PRODUCT : TURBO PROLOG NUMBER : 308
- VERSION : 1.0xx
- OS : PC-DOS
- DATE : October 9, 1986
-
- TITLE : ASSEMBLER INTERFACE
-
- The following describes how to call a Microsoft Assembler routine
- from Turbo Prolog.
-
-
- global predicates
- double(integer,integer) - (i,o) language asm
-
- goal
- write("Enter an integer"),
- readint(A),nl,
- double(A,B),
- write("Double that value is ",B),
- readchar(_).
-
- Write the following assembler routine (ASMPROG.ASM) and compile
- to object code.
-
- A_PROG SEGMENT BYTE
- ASSUME CS:A_PROG
- PUBLIC DOUBLE_0
- DOUBLE_0 PROC FAR
- PUSH BP ; save old bp
- MOV BP,SP ; set up bp to access
- parameters MOV AX,[BP]+10 ; move input
- parm to AX
- ADD AX,AX ; double AX
- LES DI,DWORD PTR [BP]+6 ; load ES,DI with pointer
- to
- ; output parameter
- MOV ES:[DI],AX ; store AX at ES:[DI]
- POP BP ; restore BP register
- RET 6 ; return, popping
- parameters
- ; off the stack.
- DOUBLE_0 ENDP
- A_PROG ENDS
- END
-
-
- Link the Prolog and the Assembler object modules together with
- the following command:
-
- C> link init+double+asmprog+double.sym,double,,prolog
-
- Now, run the program by typing "DOUBLE."
-
-
- The basic rules for interfacing assembler routines to link with
- Turbo Prolog routines are as follows:
-
- 1) Make sure that all sub-routines are 'PROC FAR', because
- Turbo Prolog uses FAR calls exclusively.
-
- 2) Save the BP upon entrance to the Assembler program,
- and restore it on exit.
-
- 3) On exit, clear the stack with a RET X, where X is equal
- to number of bytes used by the parameters.
-
-