Example of Passing Basic String Descriptor to MASM (Far) (49382)



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 Q49382

SUMMARY

The two programs shown below demonstrate how a Microsoft Basic program passes a string descriptor to assembly language by far reference.

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 BSTRF.BAS, which passes a string descriptor (of a variable-length string) to assembly language by far reference:
    A$ = "This is the String" + "$"    ' "$" terminates the string for
                                      ' INT call
   CALLS RString(A$)   ' CALLS passes far address
   END
				
The following program is ASTRF.ASM, which gets a Basic string descriptor, then prints the string:
; The following handy .MODEL directive is found in MASM 5.10 but not
; in earlier versions:
.MODEL MEDIUM, Basic
.CODE
        PUBLIC RString
RString PROC
        push bp
        mov bp, sp       ; set stack frame
        push ds
        mov ds, [bp+8]   ; segment of descriptor
        mov bx, [bp+6]   ; offset of descriptor
        mov dx, [bx+2]   ; address of actual 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 BSTRF.BAS;
MASM ASTRF.ASM;
LINK BSTRF ASTRF;

BSTRF.EXE produces the following output:
This is the string

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB49382