Q(uick)BASIC Routine: StringAddress
Quick View
StringAddress
This routine is used in mixed-language programming. A non-BASIC routine uses StringAddress to find the far address of a BASIC variable-length string
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- far-address = StringAddress(string-descriptor%);
Description/Parameter(s)
- The preceding syntax is for the C language.
- For C, MASM, Pascal, and FORTRAN examples, see Chapter 13, "Mixed-Language Programming with Far Strings" in the Programmer's Guide.
Usage Notes
- Calls to the StringAddress routine are always made from a non-BASIC routine to find the address of a string that was transferred to BASIC from the non-BASIC routine.
- Note: If you are not doing mixed-language programming, there is usually no reason to use StringAddress. Within BASIC, you can use SSEGADD to find the far address of a variable-length string.
- As an example, assume that you have passed a string from a MASM routine to BASIC's string space using StringAssign. The descriptor for the string exists at offset descriptor. MASM can find the far address of the string data by using the following code:
- .modelextrn stringaddress: far.code
lea ax, descriptor ; offset of descriptor
push AXCALL stringaddress
- For detailed instructions on mixed-language programming with strings, see Chapter 12, "Mixed-Language Programming" and Chapter 13, "Programming with Near Strings" in the Programmer's Guide.
Example
This example uses the StringAddress routine to pass a BASIC string to an assembly-language program. The StringLength routine is used to determine the length of the string.
Note: To use this program, you must compile the following code and link it with the assembled MASM program (shown below in remarks) and the appropriate runtime library (BCL71ENR.LIB).
DEFINT A-Z
'Create a variable-length string.
Message1$ = "This string was sent to MASM for printing."
'Pass it to MASM to be printed.
CALL PrintMessage1(Message1$)
'; *************************PrintMessage1************************
'; This MASM procedure prints a string passed to it by BASIC.
'
' .model medium, basic ;Use same model as BASIC
';Define external (BASIC library) procedures
' extrn StringAddress: far
' extrn StringLength: far
'
' .code
';Define procedure with one word argument
'PrintMessage1 proc uses ds, descriptor
'
' mov ax, descriptor ;Find length of string.
' push ax
' call StringLength
' push ax ;Save length on stack.
'
' mov ax, descriptor ;Go find out the
' push ax ;address of the string
' CALL StringAddress ;data.
'
' mov ds, dx ;Address of string.l.
' mov dx, ax
' mov bx, 01 ;Handle of printer.
' pop cx ;Length of string.
' mov ah, 40h ;Have DOS print it.
' int 21h
' ret
'PrintMessage1 endp
'
' end