Microsoft KB Archive/64428

= Assembly Function Returning Variable-Length String to Basic =

Article ID: 64428

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 Q64428



SUMMARY
The two programs below demonstrate how an assembly language function can return a variable-length string to a Microsoft Basic program.

Note: This routine will not work inside the QuickBasic Extended environment (QBX.EXE) or when compiled using the Far Strings option (BC /Fs) in Microsoft Basic Professional Development System (PDS) version 7.00 or 7.10. For information on interlanguage programming with far strings in Microsoft Basic PDS, see Chapter 13, &quot;Mixed Language Programming with Far Strings,&quot; in the &quot;Microsoft Basic 7.0: Programmer's Guide&quot; for versions 7.00 and 7.10.

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 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, query in the Microsoft Knowledge Base using the following word:

BAS2MASM

Code Example
The following Basic program is SFUNC.BAS, which displays a variable-length string returned from an assembly language function (QPrint). DECLARE FUNCTION QPrint$(slen%) CLS FOR i% = 1 to 3 TString$ = QPrint$(i%) ' i% is the length of the string PRINT TSTring$, LEN(TString$) NEXT The following assembly language program is ASTR.ASM, which contains the function QPrint. The QPrint function returns a string, and the passed integer parameter (argument) returns the length of the string. ; The following handy .MODEL MEDIUM,Basic directive is found in MASM .MODEL MEDIUM, Basic .DATA str     db 10 dup (?)    ; my own string mystring dw ? ; my own descriptor (length) dw ? ; (offset)
 * 5.10 but not in earlier versions:

.CODE PUBLIC QPrint QPrint PROC push bp       mov bp, sp        push ds        push es

mov bx, [bp+6]     ; get the ptr to the string descriptor. mov cx, [bx]

push ds       pop es                    ; set es = ds

mov di, offset dgroup:str ; load the offset into di       mov al, 'a'               ; load character to fill rep stosb                ; store &quot;a&quot; into the string mov cx, [bx]             ; put the length in cx again mov bx, offset dgroup:mystring ; put offset of string ; descriptor in bx        mov [bx], cx                   ; length in first two bytes mov [bx+2], offset dgroup:str ; offset into second two bytes mov ax, bx                    ; load address of descriptor ;  into ax        pop es        pop ds        pop bp

ret 2 QPrint ENDP END To demonstrate these programs from an .EXE program, compile and link as follows:

BC SFUNC.BAS;

MASM ASTR.ASM;

LINK SFUNC ASTR;

SFUNC.EXE produces the following output:

a

aa

aaa

Additional query words: QuickBas BasicCom

Keywords: KB64428

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.