Microsoft KB Archive/49392

From BetaArchive Wiki
Knowledge Base


Example of Passing User-Defined Type from Basic to MASM (Far)

Article ID: 49392

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 Q49392

SUMMARY

The two programs shown below demonstrate how a Microsoft Basic program passes a user-defined type to assembly language by far 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 UFAR.BAS, which passes a user-defined type to assembly language by far reference:

   DEFINT A-Z
   DECLARE SUB MasmSub (BYVAL segment, BYVAL offset)
   TYPE mixed
      i AS INTEGER
      l AS LONG
      s AS SINGLE
      d AS DOUBLE
      fx AS STRING * 19
   END TYPE
   DIM dummy AS mixed
   CLS
   PRINT "Calling assembly routine to fill the user-defined type."
   CALL MasmSub(VARSEG(dummy), VARPTR(dummy))
   PRINT "Values in user-defined type:"
   PRINT "Integer: ", dummy.i
   PRINT "Long: ", dummy.l
   PRINT "Single: ", dummy.s
   PRINT "Double: ", dummy.d
   PRINT "fixed-length String: ", dummy.fx
   END
                

The following program is UAFAR.ASM, which gets a user-defined type by far reference and copies data into it:

.MODEL MEDIUM
          usrdefType   STRUC
                       iAsm       DW 10
                       lAsm       DD 43210
                       sAsm       DD 32.10
                       dAsm       DQ 12345.67
                       fxAsm      DB 'Fixed-length string'
          usrdefType   ENDS
.DATA
          AsmRec usrdefType <>

          PUBLIC MasmSub
MasmSub   PROC FAR
          push bp
          mov  bp,sp
          push es
          push di
          push si
          push cx

          mov es,[bp+8]         ; get segment of user-defined type
          mov di,[bp+6]         ; get offset of user-defined type
          mov si,OFFSET AsmRec
          mov cx,37             ; size of structure
          rep movsb             ; copy values to Basic variable

          pop cx
          pop si
          pop di
          pop es
          pop bp
          ret 4
MasmSub   ENDP
          END
                

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

BC /O UFAR.BAS;
MASM UAFAR.ASM;
LINK UFAR UAFAR;


UFAR.EXE produces the following output:

     Integer:   10
     Long:      43210
     Single:    32.10
     Double     12345.67
     fixed-length String:  Fixed-length string
                


Additional query words: QuickBas BasicCom

Keywords: KB49392