Example of Assembly Function Returning Long Integer to Basic (64105)






This article was previously published under Q64105

SUMMARY

The two programs below demonstrate how an assembly language function can return a long integer to a Microsoft Basic program.

This information about interlanguage calling applies to QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS, to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2, and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.

MORE INFORMATION

For more information about passing other types of parameters between Basic and MASM, query in the Microsoft Knowledge Base using the following word:

BAS2MASM

Code Example

The following Basic program is IFUNC.BAS, which displays a long integer returned from an assembly language function:
   DECLARE FUNCTION QPrint&

   FOR i% = 1 to 5
      PRINT QPrint&
   NEXT
				
The following program is AINT.ASM, which will return a long integer parameter when called:
; The following handy .MODEL MEDIUM,Basic directive is found in
; MASM 5.10 but not in earlier versions:
.MODEL MEDIUM, Basic
.DATA
        longnum dd 12345

.CODE
        PUBLIC QPrint
QPrint  PROC
        mov ax, WORD PTR longnum        ; return value in ax and
        mov dx, WORD PTR longnum + 2    ;   dx registers
        ret
QPrint  ENDP
        END
				
To demonstrate these programs from an .EXE program, compile and link as follows:
   BC IFUNC.BAS;
   MASM AINT.ASM;
   LINK IFUNC AINT;
				
IFUNC.EXE produces the following output:
   12345
   12345
   12345
   12345
   12345
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB64105