Dynamic Arrays?!

 BBS: Inland Empire Archive
Date: 05-14-92 (22:39)             Number: 160
From: MATT HART                    Refer#: NONE
  To: MICHAEL MALLEY                Recvd: NO  
Subj: Dynamic Arrays?!               Conf: (2) Quik_Bas
 MM> unsure, isn't there a way that you can pass the address of the array to
 MM> the procedure?

The best way to pass the address of an array is the SEG directive:

CALL MyRoutine(SEG Array(Element))

In assembly, this passes a far address to that element and
subsequent elements will follow sequentially.  Retrieve it
with an LES.

MyRoutine PROC Array:DWord
     LES  DI,Array

You can also pass by using VARSEG and VARPTR :

CALL MyRoutine(BYVAL VARSEG(Array(El)), BYVAL VARPTR(Array(El)))

With the BYVAL keyword, a far address is passed in exactly
the same way as the SEG directive.  Retrieve with an LES.
For near strings, a pointer to the string descriptor is
passed.  But be careful - BASIC will create a temporary
string outside of the string array descriptor group when
passing single elements (I.E. MyRoutine(StrgArray(1)) ).
You must pass the address of the pointer as an integer:
CALL MyRoutine (BYVAL VARPTR(StrgArray(1)))

This gives you the string descriptor of the first array
element, with subsequent elements every 4 bytes:
MyRoutine PROC Strg:Word
     MOV       BX,Strg        ; Address of string descriptor
     MOV       CX,DS:[BX]     ; CX has len
     MOV       SI,DS:[BX+2]   ; SI has addr of 1st byte of 1st element
     MOV       DI,DS:[BX+6]   ; DI has addr of 1st byte of 2nd element
     MOV       AX,DS:[SI]     ; AX has 1st byte of 1st element
     MOV       AX,DS:[DI]     ; AX has 1st byte of 2nd element

This is near string stuff.  For far strings, it's a bit messier.
---
 * Origin: Midnight Micro!  V.32/REL  (918)451-3306 (1:170/600)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET