Example of Assembly Function Returning Integer to Basic (64429)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q64429

SUMMARY

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

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 an integer returned from an assembly language function:
   DECLARE FUNCTION QPrint%
   FOR i% = 1 to 5
      PRINT QPrint%
   NEXT
				
The following assembly language program is AINT.ASM, which contains the QPrint function. The Qprint function returns an integer.
.MODEL MEDIUM, Basic
.DATA
        shortnum dw 12345

.CODE
        PUBLIC QPrint
QPrint  PROC
        mov ax, shortnum    ; return value in ax register
        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:MinorLast Reviewed:8/16/2005
Keywords:KB64429