I have the little code snippet below:
TotalScanDepth=FootprintDistance * ScanDepth; if (Rectangular) OuterStart=(TotalScanDepth % 2) - FootprintDistance; else OuterStart=TotalScanDepth % 2 - FootprintDistance % 2;
FootprintDistance is a local constant (for that routine). Value = 16.
ScanDepth is a variable, current value = 4
Rectangular is currently true
So I expext TotalScanDepth to end up being 64. Works!
But OuterStart ends up at -16? I expected +16!
Below is what the disassembler shows (with my comments on the actual register values):
00019de6: 4618 mov r0, r3 //r0 = 4 810 OuterStart=(TotalScanDepth % 2) - FootprintDistance; 00019de8: F1BC0F00 cmp.w r12, #0 807 TotalScanDepth=FootprintDistance * ScanDepth; 00019dec: EA4F1000 lsl.w r0, r0, #4 //r0 = 64 810 OuterStart=(TotalScanDepth % 2) - FootprintDistance; 00019df0: D006 beq $C$L14 00019df2: EB0071D0 add.w r1, r0, r0, lsr #31 //r1 = r0 = 64 00019df6: F0210101 bic r1, r1, #1 //nothing happens at all ? 00019dfa: 1A40 subs r0, r0, r1 //r0 = 0 00019dfc: 3810 subs r0, #0x10 //r0 = -16 00019dfe: E000 b $C$L15
TotalScanDepth is overwritten to -16, but it is not used after this. So, what am I, or the compiler, doing wrong?
Sorry, this editor really does not want you to edit your post!