bas7ex.hlp (Topic list)
StringAddress and StringLength Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'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