flat assembler
Message board for the users of flat assembler.

Index > Main > Multidimensional arrays

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial 19 Apr 2005, 13:34
Hi.

I want to learn how to use arrays in FASM. I have the idea how to handle single-dimensional arrays, but what about multi-dimensional? I heard somewhere, that there's a trick with adding a certain number to the index as base or something. Oh... I really don't remember and I would be glad, if anyone could help. Anyway, I want to have features similar to C for example:

int myarray[10][5]

myarray[0][2]=...

If you can help me, Id be glad.
denial
Post 19 Apr 2005, 13:34
View user's profile Send private message Reply with quote
rambo



Joined: 28 Feb 2005
Posts: 22
Location: posen, poland
rambo 19 Apr 2005, 13:42
myarray[x][y] = myarray + (x * number_of_lines + y) * size_of_element

your example:
myarray[0][2] = myarray + (0 * 10 + 2) * 2, and it`s equal to:
myarray[0][2] = myarray + 4
Post 19 Apr 2005, 13:42
View user's profile Send private message Visit poster's website Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 19 Apr 2005, 13:49
Ah thank you, I think that was what I heard... But will it also work with more dimensions?
Post 19 Apr 2005, 13:49
View user's profile Send private message Reply with quote
rambo



Joined: 28 Feb 2005
Posts: 22
Location: posen, poland
rambo 19 Apr 2005, 13:59
int array[10][20][30][40]

array [a][b][c][d] = array + (a*20*30*40 + b*30*40 + c*40 + d) * size_of_element

example:
dword array[12][4][2][64]

array[10][2][0][32] = array + (10*4*2*64 + 2*2*64 + 0*2*64 + 32) * 4
Post 19 Apr 2005, 13:59
View user's profile Send private message Visit poster's website Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial 19 Apr 2005, 15:58
thank you really much :O)
Post 19 Apr 2005, 15:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.