flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tomasz Grysztar
The data defined as "virtual" is not placed in the output file, therefore any initialization done there has no effect (except for the use with "load" directive, but that's a different topic) - it only defines labels for you. To initialize data addressed by those labels correctly at run time it's the programmer's responsibility, and generally it should be done just like you did: "mov [filled],200h" etc. Since you have allocated the space for those variables manually (with "sub esp,8"), it's obvious that you have fill them with the right values manually, too.
It is possible (with clever use of "virtual" and "load" directives) to make some macros to automatically allocate and initialize local variables with the defined values, but that's a different story. |
|||
![]() |
|
Ton
Thanks a lot for your fast reply.
load loads from the compiled source or file. Thus somehow I need to set a value. Something like : virtual at esp xor eax,eax add eax, 200h load dword filled from eax end virtual How is this clever use really done? -- Ton |
|||
![]() |
|
Tomasz Grysztar
I mean something like:
Code: virtual at esp filled dd 200h size = $-esp load value dword from 0+esp end virtual push ebp mov ebp,esp sub esp,size mov dword [esp],value But to make this automated, some very complicated macro solutions would have to be applied, not sure if it's worth it. |
|||
![]() |
|
Ton
Clever !
I stick to the initial approach ![]() |
|||
![]() |
|
r22
If your code section is writeable/readable why not just have your value as part of the function rather than the stack
Code: Function: push ebp mov ebp,esp ... mov esp,ebp pop ebp retn 0 Over_Here: dd 200h |
|||
![]() |
|
Ton
Yes, that works as well, but then the executable is a bit longer.
|
|||
![]() |
|
r22
that's not true.
SUB ESP,8 takes up more bytes than a arbitrary dword value 200h after a function return. |
|||
![]() |
|
MazeGen
![]() SUB takes 3 bytes, dword value 4 bytes: 83EC 08 sub esp,8 |
|||
![]() |
|
Tomasz Grysztar
But you still have to initialize that dword with at least one more instruction, don't you?
![]() |
|||
![]() |
|
r22
Its actually
SUB ESP,8 <==This way used more often MOV ESP,200h <==Because people are funny Versus Label: dd 200h <==This way shorter MazeGen, I forgot the MOV because the space you make on the stack has to be initialized. So using the Label: DD 200h after the return is less bytes |
|||
![]() |
|
Ton
$ more try.asm
format elf executable entry main main: mov eax, 1 mov dword ebx,[a] int 80h a: dd 5 $ more try2.asm format elf executable entry main main: mov eax, 1 mov dword ebx,5h int 80h $ ll try try2 -rwxrwxr-x 1 tonl tonl 101 Mar 21 08:53 try -rwxr-xr-x 1 tonl tonl 96 Mar 21 08:55 try2 For now I think mov dword esp,200h is shorter. Best Regards, Ton |
|||
![]() |
|
Frank
For your consideration:
Code: push 200h push 0 virtual at esp fd dd ? filled dd ? end virtual Seven bytes to allocate space for, and initialize both variables. If you don't care about initializing "fd", then use "push eax" instead of "push 0", and it's down to six bytes. For small initialization values (-128 to +127) it's even less -- "push 127 / push eax" takes three bytes. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.