This feature request is a more general version of bug #1058509, which was partially solved. It also applies to MPASM, and the negative effects may not justify the amount of effort required to fix it.
Several directives assume a default value (0 right now) for their arguments on the first pass if they contain forward references. For a genuine forward reference (as opposed to an undefined value), the value will be known on the second pass. However, in many cases the default value will have side effects that will cause a redefinition error:
org 0
#if lbl == 0
nop
#endif
failing_lbl:
org 0x800
lbl:
end
On the first pass, lbl will be assumed 0, and failing_lbl will be address 1. On the second pass, lbl will be known to be address 0x800 and failing_lbl will be address 0. However, this code is valid because lbl has a fixed value and should never be assumed 0 (or any other value).
There are very similar cases that create dependency cycles and therefore justify a redefinition error:
org 0
#if failing_lbl == 0
nop
#endif
failing_lbl:
To correctly handle the valid code would probably require some sophisticated dependency analysis that would not be feasible with gpasm's 2-pass architecture, but the architecture may change in the future.
Anonymous
Logged In: YES
user_id=896846
Originator: YES
Constants defined with the EQU and ORG directives have the same issue. Under MPASM, they will be treated as if they were defined from the beginning of the file. gpasm will only consider them defined below the line they are defined on:
Last edit: Borut Ražem 2013-01-03