flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Tomasz Grysztar 15 Mar 2005, 13:48
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 15 Mar 2005, 14:33
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 15 Mar 2005, 15:42
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 15 Mar 2005, 17:16
Clever !
I stick to the initial approach ![]() |
|||
![]() |
|
r22 16 Mar 2005, 06:33
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 16 Mar 2005, 07:50
Yes, that works as well, but then the executable is a bit longer.
|
|||
![]() |
|
r22 17 Mar 2005, 06:09
that's not true.
SUB ESP,8 takes up more bytes than a arbitrary dword value 200h after a function return. |
|||
![]() |
|
MazeGen 18 Mar 2005, 17:58
![]() SUB takes 3 bytes, dword value 4 bytes: 83EC 08 sub esp,8 |
|||
![]() |
|
Tomasz Grysztar 18 Mar 2005, 18:12
But you still have to initialize that dword with at least one more instruction, don't you?
![]() |
|||
![]() |
|
r22 18 Mar 2005, 21:56
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 21 Mar 2005, 07:57
$ 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 23 Mar 2005, 17:40
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.