flat assembler
Message board for the users of flat assembler.
Index
> Main > Printing all elements of array |
Author |
|
MHajduk 20 Apr 2012, 18:07
This works for me:
Code: format PE console 4.0 include 'win32a.inc' entry start section '.data' data readable array db "1a2b3c4d",0 fmt db "%c",0 section '.code' readable executable start: mov ecx, 0 mainLoop: cmp ecx, 8 jne print je okay print: lea eax, [ecx + array] push ecx cinvoke printf, fmt, [eax] pop ecx inc ecx jmp mainLoop okay: invoke ExitProcess, 0 section '.idata' data import readable writeable library kernel32, 'kernel32.dll', msvcrt, 'msvcrt.dll' import kernel32, ExitProcess, 'ExitProcess' import msvcrt, printf, 'printf' |
|||
20 Apr 2012, 18:07 |
|
TmX 20 Apr 2012, 19:10
Ah I see. "lea eax [ecx + array]" means to load N-th element of the array into eax.
But why push ecx and pop ecx are also needed? |
|||
20 Apr 2012, 19:10 |
|
MHajduk 20 Apr 2012, 19:14
TmX wrote: But why push ecx and pop ecx are also needed? |
|||
20 Apr 2012, 19:14 |
|
Enko 20 Apr 2012, 20:12
In WinApi; esi, edi and ebx are the only register preserved. Other may and certenly will be modified by the function called in the api.
in your case, is better to use one of the preserved registers, so you don´t need to make the push pop. |
|||
20 Apr 2012, 20:12 |
|
MHajduk 20 Apr 2012, 20:16
Yes, that's true. I just didn't want to change TmX's source too much (for clarity) and made only most important corrections.
|
|||
20 Apr 2012, 20:16 |
|
TmX 22 Apr 2012, 02:58
Enko wrote: In WinApi; esi, edi and ebx are the only register preserved. Other may and certenly will be modified by the function called in the api. Ah yes, I totally forget about this part. Thanks. |
|||
22 Apr 2012, 02:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.