This code is very hard to understand. N
is surely not a global variable. It is rather a compile time "variable".
The situation you are witnessing is the discrepancy between a global variable and a compile time symbolic value - either defined with EQU
or =
(Quoting from the MASM 6.1 Programmers.Guide.PDF).
You can define symbolic integer constants with either of the data assignment directives, EQU or the equal sign (=). These directives assign values to symbols during assembly, not during program execution. Symbolic constants are used to assign names to constant values. [...]
and
The directives EQU and = have slightly different purposes. Integers defined with the = directive can be redefined with another value in your source code, but those defined with EQU cannot. Once you’ve defined a symbolic constant with the EQU directive, attempting to redefine it generates an error.
So what happens in you code is, that the initial value N=8
- which is output in your first call writeDec
- is changed by the following N=N-2
to N=6
.
Thing is that these symbolic integer constants (defined by =
) are changed linearly with the program definition: so N
will change its value to 6
after its re-definition, linearly! The value is (re)defined in relation to the linear program definition; and not the program flow, which will be determined at run-time.
So you have a loop in your program flow, but a sequence in your program definition! (Your source code is a linear text file.) So once N
was changed the first time by N=N-2
in the linear program definition at compile time, it won't be changed again, because this change would have to happen at run-time.