Generated Code
I've noticed that runtime code is sometimes generated even when everything could be evaluated at compile time. For example:
finishAt VAR Byte
minValue CON 5
finishAt = minValue + 1
Generates runtime code to evaluate (minValue +1). I can code this as:
finishAt VAR Byte
minValue CON 5
finValue CON minValue +1
finishAt = finValue
and avoid the runtime addition but this makes the source code longer and often obscures the intent. Are there any plans to improve SX/B by evaluating constant expressions at compile time? If not, are there other "gotchas" that I can avoid to reduce my code size?
finishAt VAR Byte
minValue CON 5
finishAt = minValue + 1
Generates runtime code to evaluate (minValue +1). I can code this as:
finishAt VAR Byte
minValue CON 5
finValue CON minValue +1
finishAt = finValue
and avoid the runtime addition but this makes the source code longer and often obscures the intent. Are there any plans to improve SX/B by evaluating constant expressions at compile time? If not, are there other "gotchas" that I can avoid to reduce my code size?
Comments
· I'm not sure what you are looking at, but the compiler does genererate the same code as a direct assignment of a constant.
· See the hex code that is generated.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
There is a fine line between arrogance and confidence. Make sure you don't cross it...
·
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 8_000_000
minValue CON 5
minValue4 CON minValue -4
finishAt VAR Word
Program Start
Start:
finishAt = minValue -4
finishAt = minValue4
Compiles to:
MOV finishAt_LSB,#minValue & 255 ;finishAt = minValue -4
MOV finishAt_MSB,#minValue >> 8
SUB finishAt_LSB,#4 & 255
SUBB finishAt_MSB,/C
SUB finishAt_MSB,#4 >> 8
MOV finishAt_LSB,#minValue4 & 255 ;finishAt = minValue4
MOV finishAt_MSB,#minValue4 >> 8