flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Simple array

Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 133
Hello, I would like to know how to make simple arrays in FASM, a bit like "C":
int MyArray[size];
I remember a tutorial that spoke in a way like that:
MyArray dw ?,?,?,?,?,?
But it's not working. Could you help me, please?
Tanks Smile

_________________
The best way to predict the future is to invent it.
Post 12 Feb 2018, 20:56
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1388
Location: Toronto, Canada
Code:
MyArray rw 16 ; 16 WORDs
Post 13 Feb 2018, 01:05
View user's profile Send private message Send e-mail Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
Thanks for the answer, that's great Smile
But how can you change this array now?
like that ? :
Code:
push MyArray mov MyArray[0], 4 add MyArray[0], 6

_________________
The best way to predict the future is to invent it.
Post 13 Feb 2018, 08:23
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
Mino
Code:
;push MyArray <-- ? mov [MyArray+0], 4 add [MyArray+0], 6 mov bx,MyArray mov [bx+10], word 4 add word [bx+4], 6 xor di,di lea si,[MyArray] mov word [si+di], 4 add [si+di], word 6


Last edited by Mikl___ on 13 Feb 2018, 09:13; edited 2 times in total
Post 13 Feb 2018, 08:58
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
EDIT:
It works! Thank you very much:)
Post 13 Feb 2018, 09:10
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
mino,
not at all!
An array of 13 words can be declared like this
Code:
MyArray dw 13 dup(?)
Post 13 Feb 2018, 09:15
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
If it is not too much to ask, could you give a concrete example? With for example an array of Hello World in different languages, then display them?
So I can understand better.
Thanks to you Smile
Post 13 Feb 2018, 09:28
View user's profile Send private message Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 168
Location: N 5.43564° E 100.3091°
I dug out something written about a decade ago.

Code:
;---------------------------------------------------------- ; Program Name: arrayofintegers.asm ; Date : August 2008 ; Author : Yeoh HS ; FASM : Built using Flat Assembler version 1.67.27 ; edited and compiled with FASM's IDE. ;---------------------------------------------------------- format PE CONSOLE 4.0 entry start include 'win32axp.inc' macro showeax { pushad cinvoke printf, '%d', eax cinvoke printf, CRLF popad } .data CRLF db '',13,10,0 intarray dd 10 dup ? ; An array of 10 dwords intarray.size dd 10 ; offsetfactor dd 4 recno dd ? arrayoffset dd ? arrayhead dd ? arraypointer dd ? .code start: ; Fills an array with values 1 to 10 mov esi, intarray ; esi = start of array mov ebx, 0 ; ebx = pointer to array item mov edx, 1 ; edx = value to put in array mov ecx, [intarray.size] ; ecx = array item count L0: mov [esi+ebx], edx ;store a value in an array position add ebx, 4 ;move array pointer to next position, 4 bytes size add edx, 1 ;increment the data to be stored by 1 loop L0 ;loop to store new data ; Loop through and print each integer mov esi, intarray ; esi has start of array mov ebx, 0 ; pointer is a 0 location mov ecx, [intarray.size] ; store array size in ecx L1: mov eax, [esi+ebx] ;point to an array element showeax ;show an array element add ebx, 4 ;move pointer to next dword value loop L1 ;point to the next array element ; Loop through backwards and print each integer mov esi, intarray ; esi has start of array mov eax, [intarray.size] ; mov 10 into eax mul [offsetfactor] ; mul 10 by 4 so eax now is 40 sub eax, 4 ; eax now is 36, the last position in the integer array mov ebx, eax ; set pointer to last dword value mov ecx, [intarray.size] ; store array size in ecx L2: mov eax, [esi+ebx] ; point to the last element showeax ; display it sub ebx, 4 ; move pointer backwords 1 dword loop L2 ; display the previous element ; Loop through to find an integer, 6 mov edx, 6 ; mov 6 into comparison variable mov esi, intarray ; point to start of array mov ebx, 0 ; set point to first element mov ecx, [intarray.size] ; store array size in ecx L3: mov eax, [esi+ebx] ; get an element cmp eax, edx ; compare it with value in edx je L4 ; if equal jump to L4 and show value add ebx, 4 ; move pointer to next element loop L3 ; loop back to get another element jmp L5 ; if not found jmp L5 and display message L4: showeax jmp L6 L5: pushad cinvoke printf, '%s', 'Not found',0 popad L6: ; Get selected integer, the first record. mov [recno], 1 ; mov eax, [recno] ; dec eax ; array is zero-based mul [offsetfactor] ; multiply by 4 mov [arrayoffset], eax ; now offset computed ;mov [arrayoffset+4], edx mov esi, intarray ; point to start of array mov eax, [arrayhead] ; add eax, [arrayoffset] mov [arraypointer], eax mov ebx, [arraypointer] mov eax, [esi+ebx] showeax ;Insert value 7 in position no. 2 mov [recno], 2 mov eax, [recno] dec eax mul [offsetfactor] mov [arrayoffset], eax ;mov [arrayoffset+4], edx mov esi, intarray mov eax, [arrayhead] add eax, [arrayoffset] mov [arraypointer], eax mov ebx, [arraypointer] mov eax, 7 mov [esi+ebx], eax ;Display value in position no. 2 mov [recno], 2 mov eax, [recno] dec eax mul [offsetfactor] mov [arrayoffset], eax ;mov [arrayoffset+4], edx mov esi, intarray mov eax, [arrayhead] add eax, [arrayoffset] mov [arraypointer], eax mov ebx, [arraypointer] mov eax, [esi+ebx] showeax cinvoke printf, ' Press the Enter key...' cinvoke getchar invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ user32, 'user32.dll',\ msvcrt, 'msvcrt.dll' include 'api\kernel32.inc' include 'api\user32.inc' import msvcrt,\ printf, 'printf',\ getchar,'getchar' ;========================================================== ; end of file

_________________
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
Post 13 Feb 2018, 12:21
View user's profile Send private message Visit poster's website Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
Mino
Quote:
an array of Hello World in different languages, then display them?
So I can understand better
Code:
format PE GUI include 'win32ax.inc' ; import data in the same section invoke MessageBox,NULL,wText1,wTitle,MB_OK retn wTitle db 'Iczelion Tutorial #2:MessageBox',0 wText1 db 87,105,110,51,50,32,65,115,115,101,109,98,108,121,32,119, 105,116,104,32,70,65,83,77,32,105,115,32,71,114,101,97,116,33,10 wText2 dw 26967, 13166, 8242, 29505, 25971, 25197, 31084, 30496, 29801, 8296, 16710, 19795, 26912, 8307, 29255, 24933, 8564, 3338 wText3 dd 5.55095E-8,1.5300999E31,1.0947971E21,3.2548056E33, 1.9689681E-19,2.21516896E8,2.0617684E-19,2.6453368E20,4.25648E-31 wText4 dq 8304954587831232855, 8583994396182930803, 5571868933434668137,7018141244139464992,8564 data import library user32,'USER32.DLL' import user32,\ MessageBox,'MessageBoxA' end data
Let's try to compile and run Image


Last edited by Mikl___ on 16 Feb 2018, 00:35; edited 7 times in total
Post 13 Feb 2018, 15:16
View user's profile Send private message Visit poster's website Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 514
Mino wrote:
If it is not too much to ask, could you give a concrete example? Thanks to you Smile
Now that you ask...
Code:
format ELF64 public main section '.data' writeable MyArray: .content db 'H','e','l','l','o',20h,'W','o','r','l','d',0ah,0 .size = ($ - .content) - 1 section '.text' executable main: sub rsp,8 ;Addressing individual byte (try byte 'W') mov al,byte[MyArray.content+6] ;copy 'W' to AL register ;do anything you want with the value in AL ;Display the entire string mov rdx,MyArray.size ;size mov rsi,MyArray.content ;address mov rdi,1 ;stdout mov rax,1 ;write syscall add rsp,8 ret


That's one way how array is actually implemented in ASM. It's in Linux ofc but just ignore it and focus on the constructions, structure, addressing and anything related to 'array'.

Is this enough for you?
Post 14 Feb 2018, 00:18
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
Thank you very much for your explanations Smile
Post 14 Feb 2018, 16:20
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
Mino,
did you try to compile and run my sample?
Post 15 Feb 2018, 00:55
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
I haven't had the time yet, and I'm unable to do it for now, or even before. I'll release the results soon, if it doesn't bother you of course Smile

_________________
The best way to predict the future is to invent it.
Post 15 Feb 2018, 09:25
View user's profile Send private message Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
Win32 Assembly with FASM is Gread, indeed ^^'!
Post 15 Feb 2018, 13:23
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
Mino,
Win32 Assembly with FASM is Great! Image
Post 15 Feb 2018, 15:29
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 133
Must be the French accent Laughing

_________________
The best way to predict the future is to invent it.
Post 15 Feb 2018, 15:53
View user's profile Send private message Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 78
Mino,
peut-être...
Post 15 Feb 2018, 22:48
View user's profile Send private message Visit poster's website 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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.