Microsoft KB Archive/49388

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 of Passing Fixed-Length String Between Basic and MASM

Article ID: 49388

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 Q49388

SUMMARY

The two programs below demonstrate how Microsoft Basic and assembly language pass fixed-length strings by near 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 BFSTRN.BAS, which creates a fixed-length string that is passed to assembly language to print and receives a fixed-length string from assembly:

   DECLARE SUB RString(BYVAL offs AS INTEGER)
   TYPE fixstring
      s AS STRING * 20
   END TYPE
   DIM a AS STRING * 20
   CLS
   a = "Basic String$"      ' "$" terminates string for assembly
   CALL RString(VARPTR(a))
   END
   SUB BasicSub(a AS fixstring)
      LOCATE 2, 1    ' Must LOCATE because print in assembly won't move
      PRINT a.s      '   Basic's screen position
   END SUB
                

The following program is AFSTRN.ASM, which gets a fixed-length string by near reference, prints the string, then passes a string to a Basic subprogram:

; The following handy .MODEL directive is found in MASM 5.10 but not
; in earlier versions:
.MODEL MEDIUM, Basic
EXTRN BasicSub:PROC
.DATA
  astr  DB 'Assembly String      '

.CODE

        PUBLIC RString
RString PROC
        push bp
        mov bp, sp           ; set stack frame
        mov dx, [bp+6]       ; address of string
        mov ah, 9            ; DOS interrupt to print string
        int 21h

        mov ax, OFFSET astr  ; address of assembly string
        push ax              ; pass it to Basic
        call BasicSub

        pop bp
        ret 2
RString ENDP

        END
                

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

BC BFSTRN.BAS;
MASM AFSTRN.ASM;
LINK BFSTRN AFSTRN;


BFSTRN.EXE produces the following output:

Basic String
Assembly String



Additional query words: QuickBas BasicCom

Keywords: KB49388