I want translate C into asm.But how can i stimulate stack and array(int a)?
thanks!
Posted on 2007-04-27 08:42:02 by ekin
It is really simple. The size of that array is L*X*Y where:

L = Length of the each element of an array (For example, DWORD has the L of 4, WORD has the L of 2, Byte has the L of 1)
X = The number of elements in the first dimension of the array. For example INT X[10][20] has the X of 10.
Y = Is the number of elements in the second dimension of the array. INT X[10][20] has the Y of 20.

So to calculate the length of the array INT X[10][20], assuming that INT is interpreted as a DWORD in your compiler, the length is:
4*10*20 = 800 Bytes.

Now what you will do is that you will allocate 800 bytes either in the stack or your data segment. Now you will access the array in rows and columns. For example Row0 Column0 will be the first byte of the array to the fourth byte (INT is 4 bytes long), Row0 Column1 will be the fifth byte to the 8th byte and so on.

I recommend that you write a program like this:

``Var  Array1   : Array[0..9, 0..19] of DWORD;  CounterX : Cardinal;  CounterY : Cardinal;beginFor CounterX := Low(Array1) to High(Array1) do  begin    For CounterY := Low(Array1) to High(Array1) do      begin        Array1 := 0;      end;  end;end;``

In a high level language such as Delphi and then watch how the compiler compiles this for you. You will learn an awful lot about n-dimensional arrays by looking at the disassembled code generated by a HLL.

In case you are wondering how you should allocate stack memory in order to allocate a local array: I have written an article about this which I think will help you:

16-bit and 32-bit Stack Memory Allocation

If you also want to know how to actually access arrays of n-dimensions in Assembly, I have written an article about that too which I belive will help you:

Accessing Arrays in Assembly

Good luck.
Posted on 2007-04-27 10:10:31 by XCHG
:DThank a million!XCHG I do not what to say right now.Thank you.I learned a lot
Posted on 2007-04-28 03:48:20 by ekin