Page 1 of 1

[OK]Constant folding efficiency.

Posted: 27 Jul 2008 09:13
by Dany
Hi,

Only for your info:

Apparently this code is compiled more efficient (less rom)

Code: Select all

const __HexOffset = Ord('A') - 10;
...
Tmp := Tmp + __HexOffset;
than this one:

Code: Select all

Tmp := Tmp + Ord('A') - 10;


Declaring "Ord('A') - 10" as an actual constant does the constant folding, using "Ord('A') - 10" directly in the code does not perform constant folding. Observed in the assembly code.

MicroPascal version 8.0.0.1, PIC = 16F628A.

Posted: 27 Jul 2008 12:03
by yo2lio
Try this :

Code: Select all

Tmp := Tmp + (Ord('A') - 10);
:wink:

Posted: 27 Jul 2008 15:55
by Dany
Great. Thanks. :D