Example of Passing Variable-Length String from Basic to MASM (49396)



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 Q49396

SUMMARY

The two programs below demonstrate how a Microsoft Basic program passes a variable-length string to assembly language by near reference.

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 BSTR.BAS, which passes the offset of a variable-length string to assembly language:
   DECLARE SUB RString(BYVAL soff AS INTEGER)
   A$ = "This is the string" + "$"  ' "$" terminates string for INT call
   CALL RString(SADD(A$))
   END
				
The following program is ASTR.ASM, which gets the address of a variable-length string and prints the string out:
.MODEL MEDIUM
.CODE
        PUBLIC RString
RString PROC
        push bp
        mov bp, sp           ; set stack frame
        mov dx, [bp+6]       ; get offset to string
        mov ah, 9            ; DOS interrupt to print string
        int 21h
        pop bp
        ret 2
RString ENDP
        END
				
To demonstrate these programs from an .EXE program, compile and link as follows:
   BC BSTR.BAS;
   MASM ASTR.ASM;
   LINK BSTR ASTR;
				
BSTR.EXE produces the following output:

This is the string


Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB49396