The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: shashank_tulsyan on November 21, 2006, 05:01:25 PM

Title: Array in asm
Post by: shashank_tulsyan on November 21, 2006, 05:01:25 PM
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
Title: Re: Array in asm
Post by: TNick on November 21, 2006, 05:05:04 PM
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
Title: Re: Array in asm
Post by: Kongbo on November 22, 2006, 05:07:28 AM
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.

Title: Re: Array in asm
Post by: Tedd on November 22, 2006, 11:51:16 AM
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.
Title: Re: Array in asm
Post by: Kongbo on November 27, 2006, 09:46:38 AM
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:
Title: Re: Array in asm
Post by: TNick on November 27, 2006, 10:08:46 AM
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
Title: Re: Array in asm
Post by: hutch-- on November 28, 2006, 02:23:22 AM
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.