flat assembler
Message board for the users of flat assembler.
Index
> Windows > Simple array |
Author |
|
AsmGuru62 13 Feb 2018, 01:05
Code: MyArray rw 16 ; 16 WORDs |
|||
13 Feb 2018, 01:05 |
|
Mino 13 Feb 2018, 08:23
Thanks for the answer, that's great
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. |
|||
13 Feb 2018, 08:23 |
|
Mikl___ 13 Feb 2018, 08:58
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 |
|||
13 Feb 2018, 08:58 |
|
Mino 13 Feb 2018, 09:10
EDIT:
It works! Thank you very much:) |
|||
13 Feb 2018, 09:10 |
|
Mikl___ 13 Feb 2018, 09:15
mino,
not at all! An array of 13 words can be declared like this Code: MyArray dw 13 dup(?) |
|||
13 Feb 2018, 09:15 |
|
Mino 13 Feb 2018, 09:28
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 |
|||
13 Feb 2018, 09:28 |
|
yeohhs 13 Feb 2018, 12:21
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 |
|||
13 Feb 2018, 12:21 |
|
Mikl___ 13 Feb 2018, 15:16
Mino
Quote: an array of Hello World in different languages, then display them? 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 Last edited by Mikl___ on 16 Feb 2018, 00:35; edited 7 times in total |
|||
13 Feb 2018, 15:16 |
|
fasmnewbie 14 Feb 2018, 00:18
Mino wrote: If it is not too much to ask, could you give a concrete example? Thanks to you 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? |
|||
14 Feb 2018, 00:18 |
|
Mino 14 Feb 2018, 16:20
Thank you very much for your explanations
|
|||
14 Feb 2018, 16:20 |
|
Mikl___ 15 Feb 2018, 00:55
Mino,
did you try to compile and run my sample? |
|||
15 Feb 2018, 00:55 |
|
Mino 15 Feb 2018, 09:25
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
_________________ The best way to predict the future is to invent it. |
|||
15 Feb 2018, 09:25 |
|
Mino 15 Feb 2018, 13:23
Win32 Assembly with FASM is Gread, indeed ^^'!
|
|||
15 Feb 2018, 13:23 |
|
Mikl___ 15 Feb 2018, 15:29
Mino,
Win32 Assembly with FASM is Great! |
|||
15 Feb 2018, 15:29 |
|
Mino 15 Feb 2018, 15:53
Must be the French accent
_________________ The best way to predict the future is to invent it. |
|||
15 Feb 2018, 15:53 |
|
Mikl___ 15 Feb 2018, 22:48
Mino,
peut-être... |
|||
15 Feb 2018, 22:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.