flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Changing numerical constants: An unexpected order effect |
Author |
|
revolution 17 Jul 2005, 09:46
I don't have a solution for you but I did notice that if you put the following code at the end then the program willl compile.
Code: call TestProc An interesting problem. |
|||
17 Jul 2005, 09:46 |
|
Tomasz Grysztar 17 Jul 2005, 11:15
The problem comes from the fact that you use this code:
Code: .dStack = .dStack - (procedurename#.paramcount*4) with procedure TestProc before it gets actually defined, so during the first intermediate pass the value of .paramcount is not yet known (so is assigned to be zero). Nevertheless you then rely on value calculated this way to check the stack balance. If you remove the "halt" instruction, you will see that the message about unbalanced stack doesn't get displayed finally when you allow fasm to completely resolve the code. The illegal instruction however stops the assembly during the first pass, preventing your code from being resolved. The solution might be to replace "halt" with some instruction that cause "resolvable" error, in which case fasm doesn't report an error unless it still remains after resolving is complete - like jump out of range, or "rb" with invalid value: Code: rb -1 Or maybe I should implement "halt" internally, as decard suggested, to cause an "user error" in resolvable way. |
|||
17 Jul 2005, 11:15 |
|
Frank 17 Jul 2005, 15:32
Tomasz Grysztar wrote: The problem comes from the fact that you use this code: Tomasz, your explanation does not cover the "full story". The same line of code is also used by two procedures that compile nicely (StartProc1, StartProc3). Therefore the line alone cannot fully explain why FASM takes a different compilation path in StartProc4. A full explanation will need to account for the unexpected order effect: the same macros with the same parameters compile nicely when called in the sequence SUB-ADD-STDCALL (as in StartProc3), but lead to a completely different compilation path when called in the order SUB-STDCALL-ADD (as in StartProc4). Note that my code example has been carefully constructed such that sequence should not matter at all. Well, anyway. Your suggestion of replacing "halt" by "rb -1" makes the code compile. It is a really elegant workaround, thank you. Regards, Frank |
|||
17 Jul 2005, 15:32 |
|
Tomasz Grysztar 17 Jul 2005, 15:59
Well, I might have not been clear enough: when the expression has an value that is not yet known, it has a value of zero assigned temporarily (as this usually makes better optimization, but that's another story). So this line:
Code: .dStack = .dStack - (procedurename#.paramcount*4) assigns 0 to .dStack contant in the first pass, when the value of TestProc.paramcount is not yet known. You can easily see how setting .dStack to zero in this place leads to your problem. It goes like: Code: .dStack = .dStack + .stackdatasize .dStack = .dStack - (procedurename#.paramcount*4) ; unknown value, sets to 0 .dStack = .dStack - .stackdatasize ; sets to 0-.stackdatasize and so you get non-zero .dStack value in this case. |
|||
17 Jul 2005, 15:59 |
|
revolution 18 Jul 2005, 01:11
How about this:
Code: halt fix db -1 Then the "halt" looks good in the code and the "db -1" gives the desired effect. |
|||
18 Jul 2005, 01:11 |
|
Frank 18 Jul 2005, 04:12
Excellent -- I see it now
|
|||
18 Jul 2005, 04:12 |
|
Tomasz Grysztar 18 Jul 2005, 08:52
revolution: yes, and even the EQU will be enough, since we need this replacement at the assembly stage, not earlier. Also I would recommend the "err" name instead of "halt", as this one doesn't halt compilation and causes error only when the resolving doesn't fix it.
|
|||
18 Jul 2005, 08:52 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.