Microsoft KB Archive/49389

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 Passing Fixed-Length String from Basic to MASM (Far)

Article ID: 49389

Article Last Modified on 8/16/2005



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 Q49389

SUMMARY

The two programs shown below demonstrate how Microsoft Basic passes a fixed-length string to assembly language by far 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 BFSTRF.BAS, which creates a fixed-length string and passes it to assembly language to be printed:

   DECLARE SUB RString(BYVAL sseg AS INTEGER, BYVAL soff AS INTEGER)

   DIM a AS STRING * 20

   CLS
   a = "Basic String$" ' "$" terminates string for assembly
   CALL RString(VARSEG(a), VARPTR(a))
   END
                

The following program is AFSTRF.ASM, which gets a fixed-length string from Basic and prints it:

.MODEL MEDIUM, Basic
.CODE
        PUBLIC RString
RString PROC
        push bp
        mov bp, sp       ; set stack frame
        push ds
        mov ds, [bp+8]   ; segment of string
        mov dx, [bp+6]   ; offset of string
        mov ah, 9        ; DOS interrupt to print string
        int 21h
        pop ds
        pop bp
        ret 4
RString ENDP
        END
                

To demonstrate these programs from an .EXE program, compile and link as follows:

   BC BFSTRF.BAS;
   MASM AFSTRF.ASM;
   LINK BFSTRF AFSTRF;
                

BFSTRF.EXE produces the following output:

   Basic String
                


Additional query words: QuickBas BasicCom

Keywords: KB49389