Microsoft KB Archive/49396

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 17:56, 18 July 2020 by 3155ffGd (talk | contribs) (importing KB archive)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Base


Example of Passing Variable-Length String from Basic to MASM

Article ID: 49396

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0
  • Microsoft BASIC Professional Development System 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



Additional query words: QuickBas BasicCom

Keywords: KB49396