Other Parts Discussed in Thread: MSP430F2618
Hello,
I am working with CCS V4.0.0.16000, developing for a MSP430F2618 (X architecture) microcontroller in C and I have run into an issue with pointer math calculations generated by the compiler for what I would think should only need simple arithmetic calculations.
For this line of code:
pxLink->pxNextBlock = pxLink + pxLink->uiBlockLength;
The compiler generates the following dissassembly:
26 pxLink->pxNextBlock = pxLink + pxLink->uiBlockLength;
0x0316a: 422F MOV.W #4,R15
0x0316c: 1800 515F 0004 ADDX.A 0x00004(SP),R15
0x03172: 4F2C MOV.W @R15,R12
0x03174: 430D CLR.W R13
0x03176: 403E 0006 MOV.W #0x0006,R14
0x0317a: 430F CLR.W R15
0x0317c: 13B0 331A CALLA #__mpyl_hw
0x03180: 013E 0004 MOVA 0x0004(SP),R14
0x03184: 4D0F MOV.W R13,R15
0x03186: 0E4F RLAM.A #4,R15
0x03188: 0E4F RLAM.A #4,R15
0x0318a: 0E4F RLAM.A #4,R15
0x0318c: 0E4F RLAM.A #4,R15
0x0318e: 1800 DC4F BISX.A R12,R15
0x03192: 0FEE ADDA R15,R14
0x03194: 013F 0004 MOVA 0x0004(SP),R15
0x03198: 0E7F 0000 MOVA R14,0x0000(R15)
The assembly always produces the wrong results for the "pxLink + pxLink->uiBlockLength" part of the code which messes up everything else. Functionally the assembly multiplies the pxLink->uiBlockLength by the length of the pxLink struct. I don't understand why it would use the hardware multiplier under these circumstances at all though.
Just for some context, this code is coming out of a memory management routine that uses a linked list header in each block subdividing the heap. I have uploaded some code that exhibits this issue here. You can also take a look on pastebin: http://pastebin.com/m16b19f8a
I appreciate any help or insight into what might be causing this issue.
-Aaron