Hi again Alan,
But, back to my initial statement (Cowgol code is smaller) ... I presume that this is a typical case of code generated by two different approaches:
- HiTech C, where local variables are stored on the stack
- Cowgol, where local variables are static ( kind-of , because they are not fully static, e.g. if A calls B and C, but B does not call C and C does not call B, B and C local variables overlap each other)
... and the 'local storage' results in more compact code, due to the Z80 registers & instruction set.
In fact, I "translated" very strictly the DAIM0350 Adventure C source into Cowgol source, conserving all the data-related structures.
And, the difference in executables size is significant (45KB vs. 38.5KB).
Interestingly, more optimization could be done on the Cowgol code (so the code might be even slimmer...).
E.g. the Cowgol compiler's second step occasionally fails to assign the right registers :
Suppose I want to assign a value to a variable ( VARA := 1; ). The compiler produces often :
LD IY,1
LD (VARA),IY
instead of
LD BC,1
LD (VARA),BC
because it (wrongly) picks IY or IX (instead of BC or DE) to be used... and this results in more bytes being used (and slower exec time...)
This is not the only vulnerability of the current Cowgol compiler... I tried to compensate some of them by post-processing (with COWFIX) the temporary output of the compiler (the assembler source produced by COWLINK), but post-processing is sometimes difficult and time consuming...
In many cases I did optimize the assembler output of the compiler, in other cases I could not (see COWFIX source comments).
As a comment, COWFIX was absolutely necessary to be inserted in the Cowgol compiler toolchain, because the original output of the compiler contained some 'exotic' statements, such as 'POP B' instead of 'POP BC', and I used the occasion to do some code additional optimizations too, e.g:
RET Z
instead of:
JP NZ,label
RET
label:
Ok, enough with such boring details, thanks for following this thread,
Ladislau