flat assembler
Message board for the users of flat assembler.

 Index > Main > Multidimensional arrays
Author
 Thread
denial

Joined: 12 Sep 2004
Posts: 98
denial
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
19 Apr 2005, 13:34
rambo

Joined: 28 Feb 2005
Posts: 22
Location: posen, poland
rambo
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
19 Apr 2005, 13:42
denial

Joined: 12 Sep 2004
Posts: 98
denial
Ah thank you, I think that was what I heard... But will it also work with more dimensions?
19 Apr 2005, 13:49
rambo

Joined: 28 Feb 2005
Posts: 22
Location: posen, poland
rambo
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
19 Apr 2005, 13:59
denial

Joined: 12 Sep 2004
Posts: 98
denial
thank you really much :O)
19 Apr 2005, 15:58
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum

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

Website powered by rwasa.