Microsoft KB Archive/64106

= Sample Assembly Function Returning Single to Basic =

Article ID: 64106

Article Last Modified on 11/21/2006



This article was previously published under Q64106



SUMMARY
The two programs below demonstrate how an assembly language function can return a single-precision variable 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, search in the Microsoft Knowledge Base using the following word:

BAS2MASM

Code Example
The following Basic program is SFUNC.BAS, which displays a single-precision number returned from an assembly language function: DECLARE FUNCTION QPrint! FOR i% = 1 to 2 PRINT QPrint! NEXT The following program is ASING.ASM, which will return a single-precision number when called: ; The following handy .MODEL MEDIUM,Basic directive is found in MASM .MODEL MEDIUM, Basic .DATA singlenum dd 98.6
 * 5.10 but not in earlier versions:

.CODE PUBLIC QPrint QPrint PROC FAR push bp       mov bp, sp        push si        push di        push es

push ds        ; set es = ds        pop es

mov si, offset dgroup:singlenum mov di, [bp+6] ; load value into address at bp+6

mov cx, 4 rep movsb

mov ax, [bp+6] ; load offset of temp value in ax and mov dx, ss     ; ss into dx

pop es       pop di        pop si        pop bp        ret 2 QPrint ENDP END To demonstrate these programs from an .EXE program, compile and link as follows: BC IFUNC.BAS; MASM ASING.ASM; LINK IFUNC ASING; IFUNC.EXE produces the following output:   98.6 98.6

Additional query words: QuickBas BasicCom

Keywords: KB64106

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.