flat assembler
Message board for the users of flat assembler.

Index > Windows > Arrays in FASM?

Author
Thread Post new topic Reply to topic
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 01 Aug 2008, 17:05
Hey... well yeah, im wondering if arrays are available in fasm?

i tried something stupid like this already

Code:
format PE GUI 4.0
include '%fasminc%\win32ax.inc'

section '.data' readable writable
array dd 4,4,4,40

section '.code' code executable
        .start:
        mov dword [array],    'arr1'
        mov dword [array+4d], 'arr2'
        mov dword [array+8d], 'arr3'
        mov dword [array+12d],'arr4'
        invoke MessageBox, 0, (array),    0, 0
        invoke MessageBox, 0, (array+4d), 0, 0
        invoke MessageBox, 0, (array+8d), 0, 0
        invoke MessageBox, 0, (array+12d),0, 0
        ret
        .end .start    


^ failed miserably...

Any help?

~ illuz1oN
Post 01 Aug 2008, 17:05
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 01 Aug 2008, 17:16
I don't understand your request.
It compiles, shows: "arr1arr2arr3arr4", "arr2arr3arr4", "arr3arr4", "arr4". Everything is normal!?

What did you expect? If you are worried about the non-exiting program, then you must know that Windows wants ExitProcess on process exit. And if you need the arrays to be separated, then you must space them with NULL-chars. All is in the following code:
Code:
format PE GUI 4.0
include 'win32ax.inc'

section '.data' readable writable
array rb 20

section '.code' code executable
        .start:
        mov dword [array],    'arr1'
        mov dword [array+5d], 'arr2'
        mov dword [array+10d],'arr3'
        mov dword [array+15d],'arr4'
        invoke MessageBox, 0, (array),    0, 0
        invoke MessageBox, 0, (array+5d), 0, 0
        invoke MessageBox, 0, (array+10d),0, 0
        invoke MessageBox, 0, (array+15d),0, 0
        invoke ExitProcess,0
        .end .start
    

Displays "arr1", "arr2", "arr3", "arr4" and exits.
Post 01 Aug 2008, 17:16
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 01 Aug 2008, 17:31
no, i dont mean like that.

although it is better... i mean like

example:
the array has 5 slots.
each slot holds "Array#" # = array slot number

and then you can access the array like, mov eax, dword [array+1d]
^ probably wrong syntax for the mov, but the array+1d will access the first slot, [array+5d] the fifth slot, etc?

i hope its possible >.<
Post 01 Aug 2008, 17:31
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 01 Aug 2008, 18:41
Code:
include 'win32ax.inc'
        array   rd 4
main:
        mov     [array], 'ar0'
        mov     [array+4], 'ar1'
        mov     [array+8], 'ar2'
        mov     [array+12], 'ar3'
        invoke  MessageBox, 0, array, 0, 0
        invoke  MessageBox, 0, array+4, 0, 0
        invoke  MessageBox, 0, array+8, 0, 0
        invoke  MessageBox, 0, array+12, 0, 0
        invoke  ExitProcess, 0
.end main    


Code:
include 'win32ax.inc'
        str0    db 'Array0',0
        str1    db 'Array1',0
        str2    db 'Array2',0
        str3    db 'Array3',0

        array   rd 4
main:
        mov     [array], str0
        mov     [array+4], str1
        mov     [array+8], str2
        mov     [array+12], str3
        invoke  MessageBox, 0, [array], 0, 0
        invoke  MessageBox, 0, [array+4], 0, 0
        invoke  MessageBox, 0, [array+8], 0, 0
        invoke  MessageBox, 0, [array+12], 0, 0
        invoke  ExitProcess, 0
.end main    



Does either of these do it the way you want?
Post 01 Aug 2008, 18:41
View user's profile Send private message MSN Messenger Reply with quote
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 01 Aug 2008, 18:53
Yeah, thanks!

the second one is great Smile
Post 01 Aug 2008, 18:53
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 01 Aug 2008, 19:22
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:56; edited 1 time in total
Post 01 Aug 2008, 19:22
View user's profile Send private message Reply with quote
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 01 Aug 2008, 20:53
asmcoder, please post your version if you disagree with okasvi's, but until then -> im using okasvi's method, as its working perfectly for me.
Post 01 Aug 2008, 20:53
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 02 Aug 2008, 09:42
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:56; edited 1 time in total
Post 02 Aug 2008, 09:42
View user's profile Send private message Reply with quote
dxl



Joined: 17 Sep 2005
Posts: 16
dxl 02 Aug 2008, 09:49
Strings of chars have to be null terminated.
() aren't needed i think

It's not good to put buffers at start of a program 'cause
if you dont allocate enough bytes for your buffer the code can be owerwritten.
Post 02 Aug 2008, 09:49
View user's profile Send private message Reply with quote
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 02 Aug 2008, 10:09
asmcoder wrote:
instead of

str0 db 'Array0',0
mov [array], str0
invoke MessageBox, 0, [array], 0, 0


use invoke MessageBoxA, 0, str0, 0, 0


theres no MessageBox symbol btw.
and reserved bytes shouldnt be at the end of section?


that was his example, my situation is totally differnt.
im looping through and adding it onto an array, but i still cant do it, as i dont have any registers free to be my counter. (i need it to be +4 each time, then ' mov dword [Array+counter], ebx ')

Thanks for the help anyway guys, appreciate it! fasm rocks:)
Post 02 Aug 2008, 10:09
View user's profile Send private message Reply with quote
illuz1oN



Joined: 22 Feb 2008
Posts: 11
illuz1oN 02 Aug 2008, 11:23
sorry for the double post guys...

anyone know how to get another counter register? for some reason i can do ' mov dword [szArr+esi], ebx ' but no ' mov dword [szArr+ecx], ebx ' (probably wrong size or whatever, it just crashes anyway)

but, esi, edx, ebx, are all being used.

i've tried using al as a counter like so (its in a loop)

Code:
...
push esi ;save it from earlier use
xor esi, esi
mov byte [esi], al ;esi has number
mov dword [szArr+esi], ebx ;append onto array
add al, 4
pop esi
...
    


but that too has no effect... really confusing me..
Post 02 Aug 2008, 11:23
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.