Example of Passing Basic Two-Dimensional Integer Array to MASM (49398)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q49398

SUMMARY

The two programs shown below demonstrate how a Microsoft Basic program can pass a two-dimensional integer array to assembly language.

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 BTWODIMI.BAS, which passes an uninitialized two-dimensional integer array to an assembly routine that initializes the array:
   DECLARE SUB TwoInt(BYVAL ASeg AS INTEGER, BYVAL AOff AS INTEGER)
   DIM IntArray(1 TO 2, 1 TO 3) AS INTEGER
   CALL TwoInt(VARSEG(IntArray(1, 1)), VARPTR(IntArray(1, 1)))
   FOR row% = 1 TO 2
      FOR col% = 1 TO 3
         PRINT IntArray(row%, col%)
      NEXT
   NEXT
   END
				
The following program is ATWODIMI.ASM, which initializes a two-dimensional integer array passed from Basic:
; The following handy .MODEL MEDIUM,Basic directive is found in MASM
; 5.10 but not in earlier versions:
.MODEL MEDIUM, Basic
.DATA
        i11 DW 11
        i21 DW 21
        i12 DW 12
        i22 DW 22
        i13 DW 13
        i23 DW 23
.CODE
        PUBLIC TwoInt
TwoInt  PROC
        push bp
        mov bp, sp             ; set stack frame
        push es
        push si
        push di
        mov es, [bp+8]         ; segment of array
        mov di, [bp+6]         ; offset of array
        mov si, OFFSET i11
        mov cx, 6              ; number of items to copy
        rep movsw              ; copy data to array
        pop di
        pop si
        pop es
        pop bp
        ret 4
TwoInt  ENDP
        END
				
To demonstrate these programs from an .EXE program, compile and link as follows:
   BC BTWODIMI.BAS;
   MASM ATWODIMI.ASM;
   LINK BTWODIMI ATWODIMI;
				
BTWODIMI.EXE produces the following output:

11
12
13
21
22
23


Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB49398