for ZASM and ALASM experts
ZXNet echo conference «code.zx»
From Kirill Frolov → To All 8 September 2003
Press RESET immediately, All!
Both ZX assemblers, ZASM (version 3.10) and ALASM (version 4.x)
provide the ability to include any part of the code in
program according to the terms of use of the label. This is done in ZASM
by the IFUSED directive, in ALASM by the '?' operator calculator
(example: IF ?LABEL-1). This makes it possible to compose
libraries of useful routines and include them in the program only
in the event that they are actually used in the program.
However, there is one pitfall in this: both assemblers, and
ZASM and ALASM are essentially single-pass (ZASM is two-pass, but on
The IFUSED directive is not affected by the second pass). If
label on the first pass, at the time of execution of the conditional directive
compilation is not considered used, then its subsequent
use will not result in inclusion of text defining it.
Let's say there are two library functions arranged like this
way that the inclusion of one of them requires mandatory
inclusion of another. An example demonstrating the problem:
ifused function1
function1
call z, function2
ret
endif
ifused function2
function2
call nz, function1
ret
endif
It turns out that if the program uses funct2, then
function1 needs to be enabled, but funct1 will not be enabled,
since it is not used anywhere before its definition. Possible in
in the library file, place the function definition funct2 beforedefining the function funct1 and the problem seemed to be solved.
But then, if there is another program that explicitly uses
funct1 and not using funct2 the same problem pops up
again.
I don't have an acceptable solution yet other than to clothe every function
into two conditional compilation directives, and include the file by
several times until all labels have been identified, not
found it. It looks something like this in the library:
ifndef function
ifused function
function
xor a
ret
endif
endif
And in the main program like this:
... program text ....
call function
... program text ....
include "library.asm"
include "library.asm"
include "library.asm"
include "library.asm"
How many times library.asm needs to be enabled is determined by an experienced
by...
The problem described above is exacerbated by the fact that libraries
more than one and the connections between them are very confusing. We have to
turn them on several times intermixed. This is my decision
I really don’t like it, I want to have a simple and universal way
include only the functions I need from the library.
While I was writing the letter, the idea came up to use recursive
inclusion of library text. You just need to add it to the end
each library file is something like this:
ifused function
ifndef function
include "library.asm" ; the file is included recursively
endif
endifAnd so on for each function defined in the library. And problems
with cross references between different libraries this is not the case
decides. :-(
Can anyone suggest a more rational solution to the problem?
From Aleksey Senilov → To Kirill Frolov 9 September 2003
||*()*|| Hello, _/Kirill/_!
08 September 2003 20:07, Kirill Frolov wrote to All:
KF> Can anyone offer a more rational solution to the problem?
I usually divide all libraries into two parts: macros and code. Similar to C
these are .h and .c respectively
Macros are loaded at the beginning of the program, library code at the end.
All functions are called via macros. And in them you can take care of
defining dependent labels/functions, even through define (or equ, or
= if in Alasma).
The program itself does not have any “concerns” about supporting dependencies.
All the best! /*Gandalf*/ *Grey* was with you. ||*()*||
From Kirill Frolov → To Aleksey Senilov 11 September 2003
Press RESET immediately, Aleksey Senilov!
On Tue, 09 Sep 03 13:06:23 +0400, Aleksey Senilov wrote:
KF>> Can anyone offer a more rational solution to the problem?
AS> I usually divide all libraries into two parts: macros and code.
AS> By analogy with C, these are .h and .c, respectively
AS> Macros are loaded at the beginning of the program, library code at the end.
AS> All functions are called via macros. And in them you can take care of
AS> defining dependent labels/functions, even through define
AS> (or equ, or =, if in Alasma).
How can a tag be used in ZASM? I'm nothing
I don't know other than dw label.
AS> The program itself does not have any “worries” about supporting dependencies.
Damn it...
In order for all links to be resolved it is required that
each next used function with ifdef-enif environment
included in the text after the function using it. This
_impossible_ because there are functions with a closed chain
dependencies (for example: funct1 uses funct2, which
uses funct3, which in turn uses funct1
-- it is assumed that the program can use any of
functionN). Yes, and sort the library text in a specific wayokay too inconvenient...
It is clear that you will have to force the assembler to look through
text libraries several times until the desired effect is achieved,
the only question is how to do it.
Now my thoughts stopped at this:
(this is at the end of the main program)
rept 20
include "library1.asm"
include "library2.asm"
...
endr
It works *VERY* *slowly*. It would be faster if there was
it is known that there are no more undefined labels (the cycle can be
would have been interrupted).