"How much would the output file change if we compiled C code using the XC8 compiler?"
So I tried to compile C code that I made and compared the each output HEX file depend on each optimization level.
pic16_optimizationText.X.zip
I will use below C code, It will be friendly if you learned C language
/* TODO <INSERT USER APPLICATION CODE HERE> */ for(i=2;i<=9;i++){ for(j=2;j<=9;j++){ LATA = i*j; } } |
Now let's see the result! XC8 Compiler has three kinds of optimization level such as Free, Standard, and Professional mode
| Free mode | Standard mode | Professional mode |
Flash memory used | 80 bytes | 69 bytes | 50 bytes |
rate | 1 | 0.86 | 0.65 |
Memory Summary: Program space used 50h ( 80) of 2000h words ( 1.0%) Data space used Ah ( 10) of 3F0h bytes ( 1.0%) EEPROM space used 0h ( 0) of 100h bytes ( 0.0%) Data stack space used 0h ( 0) of 3F0h bytes ( 0.0%) Configuration bits used 0h ( 0) of 4h words ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) |
Memory Summary: Program space used 45h ( 69) of 2000h words ( 0.8%) Data space used Ah ( 10) of 3F0h bytes ( 1.0%) EEPROM space used 0h ( 0) of 100h bytes ( 0.0%) Data stack space used 0h ( 0) of 3F0h bytes ( 0.0%) Configuration bits used 0h ( 0) of 4h words ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%) |
Memory Summary: Program space used 32h ( 50) of 2000h words ( 0.6%) Data space used 7h ( 7) of 3F0h bytes ( 0.7%) EEPROM space used 0h ( 0) of 100h bytes ( 0.0%) Data stack space used 0h ( 0) of 3F0h bytes ( 0.0%) Configuration bits used 0h ( 0) of 4h words ( 0.0%) ID Location space used 0h ( 0) of 4h bytes ( 0.0%)
|
As we see the result of compiler depend on the optimization level, In case of Standard mode, The size of hex file can be reduced to 0.85 ratio. In case of Professional mode, The size of hex file can be reduced to 0.65 ratio.
As you may expect, As the size of an Hex file decreases, it will execute much more faster and save the flash memory which stores the hex file.
I think that Free mode also can use for embedded programming but if you use the standard version or professional version, you can save the flash memory and execute code much more faster.