News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Array in asm

Started by shashank_tulsyan, November 21, 2006, 05:01:25 PM

Previous topic - Next topic

shashank_tulsyan

In c++ and asm32 we can enter few elements more than the specified capacity, in an array. In asm even if we write a negative length it does work.
But, sometimes this shows errrors. Well, can anybody explain this phenomenon.
And another thing - Is there some neat way of making an expandable array in asm?
Like in java atleast, we can write one array=another; and thus the same symbol represents an array with increased dimension. Something like this in asm?
Thanks

TNick

It depends what are we talking about. If that array is in data section
.DATA
MYArray   DW  50 dup (0)

then you can use 200 bytes. The fact that you can use something like this
mov  eax, OFFSET MYArray
mov   edx, dword ptr [eax+204]

is because there is something else after that array.
.DATA
MYArray   DW  50 dup (0)
SomeVar  DW   0
SomeVar  DW   2

so, in this example, edx will hold value from SomeVar.
No one will tell you this at assamble time, but you will see the bugs after.

If you are talking about array in - let's say - a heap, then HeapAlloc may return a higher amount of memory than requested. You can find exactly how much memory you have by using HeapSize.
To "redim" a block of memory allocated with HeapAlloc, you can use HeapRealloc.

Am I off topic? Is this what you are asking?

Regards,
Nick

Kongbo

Is any other graceful way to control array?

For example :

The size of the array can be changed at any times.

We want to fill some elements into any position of this array,

We can remove any element from thr aray at any time.


Tedd

Resizable arrays are a high-level language concept.. What really happens when you compile your code is that array accesses are converted to function calls that get the array elements (or modify the array, or whatever.) So, if you try to access an element 'off the end' of the array, then the function can resize the array automagically.
We could do the same, and create a set of functions for handling this type of dynamic array - however, every time you want to access the array it must go through a function call rather than accessing directly; and there would be function calls for resizing, removing, etc.
No snowflake in an avalanche feels responsible.

Kongbo

If we cannot use it as freely as we can image, why we use it ?
If it can run fastest ONLY to crash, why we make it run ? :dazzled:

TNick

Kongbo,

You can use it or not. It's your decision.... in fact, not. Any pice of memory you use is a big array, so you will use it anyway. I would like to explain everything to you, but it will take days. As far as I see, and don't take this personal, you didn't read too much about Assambly Language. My sugestion to you is to have a good reading about it before posting questins. There are a lot of information around (use forum Search, your search engine, links at the top right corner of this page...)

PS: If you know what you're doing, it will not crash!!!

Nick

hutch--

Kongbo,

Quote
If we cannot use it as freely as we can image, why we use it ?
If it can run fastest ONLY to crash, why we make it run ? dazzled

If you need high level simplified array support, use a simplified high level language, if you need speed and power handling many different types of arrays, learn to write them in assembler.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php