flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
JohnFound 15 Oct 2003, 12:57
Hi.
I don't know about masm, but the local variables are in the stack and the ebp points to the end of the local block (stack frame). So the address of local variable is not constant and may be changed during different runs of the procedure. So there is no other way to get the address of the variable, but lea instruction. Note that you need the address of the local variable only if you want to use it as argument to another function. For other purposes you may use simply: Code: mov [.somelocal], ebx Regards |
|||
![]() |
|
roticv 15 Oct 2003, 13:18
Address of local variables?
lea eax, [ebp-8] |
|||
![]() |
|
silkodyssey 15 Oct 2003, 13:20
Thanks for replying
![]() _________________ silkodyssey |
|||
![]() |
|
JohnFound 15 Oct 2003, 13:35
[code]
lea eax, [ebp-imm8] ; 3 bytes push eax ; 1 byte ------------ total: 4 bytes push imm32 ; 5 bytes. Using local variables results 1 instruction more, but 1 byte less. ![]() |
|||
![]() |
|
silkodyssey 15 Oct 2003, 13:44
Ok thats interesting
![]() ![]() _________________ silkodyssey |
|||
![]() |
|
roticv 15 Oct 2003, 15:27
Hopefully your local variable can fit into 127bytes if not the instruction would be longer.
|
|||
![]() |
|
JohnFound 15 Oct 2003, 15:43
Well, you are right, but using local variables is good mainly not because of smaller size. It's good programming practice for every language, including assembly (or maybe particularly for assembly), especially in big projects. Using local variables make program more clear and readable and helps preventing bugs.
|
|||
![]() |
|
Tomasz Grysztar 15 Oct 2003, 16:37
You can use ADDR operator with variant of invoke macro from the "win32ax.inc" include.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.