Optimisation

As the compiler generates machine code it is possible for it to scan the code as it is compiled and to optimise the result. This process operates in a single pass, so the optimisation is limited, but never-the-less useful.

The Forth requires parameters on the stack before executing the function. If these parameters are literals it is often possible to reduce the code e.g..

 : TST $03 I/O PORTA C! ;

This would require the following code;

$0208 CALL [ DOLITERAL ]

$020C BRA $0210

$020E $03

$0210 CALL [ DOLITERAL ]

$0214 BRA $0218

$0216 $F80

$0218 RCALL [ C! ]

$021A RETURN

However, the optimizer produces:

$0200 MOVLW $03

$0202 MOVFF WREG , $0F80

$0206 RETURN

This has saved 6 words of storage and several micro seconds of execution time. It would be unusual to make this simple code a definition and so this would normally become in-line code within a larger definition. Also in this example, if the literal 03 was computed at run-time the result is already in TOS so the compiler just MOVFF TOSL , PORTA ,A and then cleans the stack. Still a significant saving.

 

Contents