flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Counter variable in forward block, impossible? |
Author |
|
revolution 18 Feb 2019, 12:18
You can do it like this:
Code: macro reserve_locals [names*] { common local size@reserve_locals virtual at ebp - size@reserve_locals forward names rd 1 common size@reserve_locals = $ - $$ end virtual if size@reserve_locals sub esp, size@reserve_locals end if } |
|||
18 Feb 2019, 12:18 |
|
Tomasz Grysztar 18 Feb 2019, 12:21
In fasm EQU defines a text substitution, therefore each of the names you define ends up becoming "ebp - size@reserve_locals" text, and you end up using the final value of "size@reserve_locals" (because it is accessed at the time when you use one of these names - remember that what is done by EQU is just to replace one text with another).
There are two possible solutions. The one I would recommend is to use LABEL AT instead of EQU, a value assigned to label is computed at the time of definition: Code: forward size@reserve_locals = size@reserve_locals + 4 label names at ebp - size@reserve_locals You could also keep using EQU and just use a local name to store the offset: Code: forward size@reserve_locals = size@reserve_locals + 4 local offset offset = -size@reserve_locals names equ ebp + offset PS. Oh, revolution's variant shows how to approach the problem in a much better way in general. Mine are more about gradually correcting your original code to show what the underlying problem was. |
|||
18 Feb 2019, 12:21 |
|
xoru 18 Feb 2019, 12:44
Thanks a tonne guys, these different solutions really give me a nice perspective on this issue. I think I totally misunderstood equ up until now, that explains a lot of trouble from the past!
Cheers! |
|||
18 Feb 2019, 12:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.