Topic : The GFA-Basic Compendium
Author : GFA Systemtechnik GmbH
Version : GFABasic.HYP v2.98 (12/31/2023)
Subject : Documentation/Programming
Nodes : 899
Index Size : 28056
HCP-Version : 3
Compiled on : Atari
@charset : atarist
@lang :
@default : Document not found
@help : Help
@options : +g -i -s +z
@width : 75
@hostname : STRNGSRV
@hostname : CAB
@hostname : HIGHWIRE
@hostname : THING
View Ref-FileMath with numbersa%=10+4*1-6/7 !for example, is converted into:
moveq #13,d0
move.l d0,adr_of_variable
That's quite an impressive optimization.
Say you are dealing with some structure, and you prefer to write like this for
clearity:
LONG{struct%+0}=22
LONG{struct%+4}=5 !etc...
The +0 in the first line generates no code at all when compiled.
IF/ENDIF versus SELECT/CASEIf you have an IF/ENDIF structure that does 2 or more tests on the same
variable, SELECT/CASE should be used. Why? Because SELECT/CASE holds the
value of the variable in a register for the entire structure, where as
IF/ENDIF fetches the value of the variable at each reference.
IF/ENDIF with Boolean testsIF test!=TRUE !generates more code
IF test! !less code
IF test!=FALSE !generates more code
IFNOT test! !less code
Quick flip flagsHow to flip a boolean variable (FALSE or TRUE) in one line of code:
flag!=NOT flag!
flag&=NOT flag&
How to flip a variable used as a flag (0 or 1) in one line of code:
flag&=flag& XOR 1 (shortest when compiled)
flag&=BCHG(flag&,0)
flag&=1-flag&
Variables versus ConstantsThis is slower and generates more code:
pdomain&=281
domain_mint&=1
result&=GEMDOS(pdomain&,W:domain_mint&)
This is faster and more compact when compiled:
result&=GEMDOS(281,W:1)
Although the first example is easier to read, fetching the values of the
variables adds overhead.
Built in commands versus custom bindingsIf at all possible always use the built in commands. Built in commands pass
parameters via registers. User written routines on the other hand pass all
parameters via the stack, which is slower.