Microsoft KB Archive/44135

= Basic Program That Passes a STATIC or DYNAMIC Array to MASM =

Article ID: 44135

Article Last Modified on 11/21/2006



This article was previously published under Q44135



SUMMARY
Below is a QuickBasic program that passes a STATIC or DYNAMIC array to an assembly routine assembled with the Microsoft Macro Assembler (MASM). The assembly routine assigns a 1 to each element in the array. In the QuickBasic program, the array can be initially defined as DYNAMIC or STATIC, using REM $DYNAMIC or REM $STATIC.

This QuickBasic program can be compiled with QuickBasic Versions 4.00, 4.00b, and 4.50, Microsoft Basic Compiler Versions 6.00 and 6.00b, and with Microsoft Basic PDS Version 7.00. The assembly program should be assembled with MASM Version 5.10.



Code Examples
The following is the QuickBasic program, MAIN.BAS, which calls the assembly routine: REM Program that calls an assembly routine that fills each REM element with a 1. The segment, offset, and number of elements REM in the array need to be passed BYVAL. REM

DEFINT A-Z DECLARE SUB MasmSub (BYVAL segment, BYVAL offset, BYVAL number)

'REM $DYNAMIC    'Can be either STATIC (the default) or DYNAMIC DIM x%(1 TO 10)  'Remove comment to define array DYNAMICally

CLS PRINT &quot;Calling assembly routine to fill array elements...&quot; CALL MasmSub(VARSEG(x%(1)), VARPTR(x%(1)), 10) PRINT &quot;Values in array:&quot; FOR i = 1 TO 10 PRINT x%(i); NEXT END

The following is the assembly program, MASMSUB.ASM, which assigns 1 to each array element:


 * This assembly program loops through the array elements of an
 * integer array that is passed to it via QuickBasic and assigns a 1
 * to each element. The segment, offset, and number of elements of
 * the array need to be passed BYVAL from the QuickBasic main module.
 * the array need to be passed BYVAL from the QuickBasic main module.

.model medium .code public MasmSub MasmSub  proc                 ;can use proc far here too begin:   push bp              ;save registers for Basic mov bp,sp           ;get the stack pointer

mov es,[bp+10]      ;get segment of array mov bx,[bp+8]       ;get offset of array

mov cx,[bp+6]       ;get length of array mov al,1            ;fill array elements with 1's

next:    mov  es:[bx],al      ;put one in the array element add bx,2   ;increment counter to next array element ; -- add two bytes for integers, four bytes ; -- for single precision and long integers, ; -- and 8 bytes for double precision numbers loop next              ;loop to assign next array element pop bp              ;restore bp for Basic ret 6               ;restore stack MasmSub  endp end To compile and LINK each program, type the following MS-DOS commands:

BC MAIN;

MASM MASMSUB;

LINK MAIN+MASMSUB;

To run the resulting executable, type the following (at the MS-DOS prompt):

MAIN

Additional query words: QuickBas BasicCom

Keywords: KB44135

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.