I've been using XC8 v1.34 for a while, and since v1.41 got released I upgraded to that version instead. Just for the sake of nothing-ness, I recompiled a mature project and saw that the value under "Program Used" (in dashboard) decreased by one, so I got really curious what was optimized away (both compilers used PRO-mode optimization).

I found the menu option Windows -> Debugging -> Disassembly listing in MPLAB and in there was a clean assembler code (below each C-statement) so I cut-n-paste the contents from v1.34 and v1.41 to two separate files and ran a diff. The only thing differing is the timestamp, which was weird since MPLAB says "Program space used: 142" for v1.34 and 141 for v1.41, but the disassemblies are exactly the same.

I then try with stripping all C-lines and the header from the output with:

$ grep -v '^[0-9]*\:' 134 | grep ^[0-9] > 134_2
$ grep -v '^[0-9]*\:' 141 | grep ^[0-9] > 141_2

In the stripped files are nothing but pure assembly code. So I check again:

$ wc -l *_2
 139 134_2
 139 141_2
 278 total

$ md5sum 134_2 141_2
b6aa911111d43cf5251cda7d4e871fdb  134_2
b6aa911111d43cf5251cda7d4e871fdb  141_2

I.e exactly the same code. 139 op-codes too, not 141 or 142.

Why is MPLABX reporting the wrong value?


1 Answer 1


The debugging disassembly listing only shows compiled source code. Not shown is low level initialization code which is required to get your program running, which the linker generates and combines with your code to produce the final executable. You can see the generated assembler code by selecting 'keep startup .as' in the project's linker options.

Here's the debugging disassembly listing that XC8 V1.38 gave me for a minimal PIC10F322 program:-

9:             #include <xc.h>
11:            void main(void) {
12:                return;
13:            }
01FD  2800     GOTO 0x0

Clearly this is not everything because the code at 0x0 is not shown. Looking in the window 'PIC memory Views / Program Memory' we see this:-

000 GOTO 0x1FE   (execution starts here at reset/power on)
1FD GOTO 0x0

So that's actually 4 program memory words used, though the compilation report said 3 and the disassembly listing only shows 1. I tried compiling it with XC8 V1.41 and the results were identical.

Why do both versions show 1 word less than actual memory usage? I don't know, but it's not something I would worry about. If your code is so large that one word makes a difference then you should either refactor it or change to a chip with more memory!

  • \$\begingroup\$ Seems like you're right. And, I'm not hunting for one byte optimizations here and there (got over 2K spare flash), I was just curious as to why there was a difference. \$\endgroup\$
    – bos
    Feb 15, 2017 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.