compiler generating incorrect code?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

compiler generating incorrect code?

755 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alager on Sun Jun 22 21:38:01 MST 2014
I'm writing a boot loader, and in the function that loops through and copies from "upper" flash to the destination, the compiler appears to be adding incorrectly.  I've tried simplifying and re-arranging the loop, but the compiler is insistent on adding 0x4000 instead of 0x1000.  See address below 0x88e.
I'm using LPCXpresso v6.1.4 [Build 194] [2014-01-15]

Thanks for any advice,
Aaron

198       {
          transferToFlash:
00000848:   push    {r7, lr}
0000084a:   sub     sp, #8
0000084c:   add     r7, sp, #0
200       unsigned long * fromAddress = (unsigned long *)0x40000; //starting location of our flash image
0000084e:   mov.w   r3, #262144     ; 0x40000
00000852:   str     r3, [r7, #4]
201       unsigned long toAddress = APPLICATION_START;
00000854:   mov.w   r3, #4096       ; 0x1000
00000858:   str     r3, [r7, #0]
204       for( ; (unsigned long)fromAddress <= 0x7efff;  )
0000085a:   b.n     0x894 <transferToFlash+76>
206       memcpy( buffer, fromAddress, MAX_BUFFER_SIZE);
0000085c:   movw    r3, #80 ; 0x50
00000860:   movt    r3, #4096       ; 0x1000
00000864:   ldr     r2, [r7, #4]
00000866:   mov     r0, r3
00000868:   mov     r1, r2
0000086a:   mov.w   r2, #4096       ; 0x1000
0000086e:   bl      0xb6c <memcpy>
209       myWriteFlash( toAddress, buffer, MAX_BUFFER_SIZE );
00000872:   ldr     r0, [r7, #0]
00000874:   movw    r1, #80 ; 0x50
00000878:   movt    r1, #4096       ; 0x1000
0000087c:   mov.w   r2, #4096       ; 0x1000
00000880:   bl      0x44c <myWriteFlash>
212       toAddress+= 0x1000;
00000884:   ldr     r3, [r7, #0]
00000886:   add.w   r3, r3, #4096   ; 0x1000          <-- this is correct
0000088a:   str     r3, [r7, #0]
213       fromAddress+= 0x1000;
0000088c:   ldr     r3, [r7, #4]
0000088e:   add.w   r3, r3, #16384  ; 0x4000          <-- this should be 0x1000 or #4096
00000892:   str     r3, [r7, #4]
204       for( ; (unsigned long)fromAddress <= 0x7efff;  )
00000894:   ldr     r2, [r7, #4]
00000896:   movw    r3, #61439      ; 0xefff
0000089a:   movt    r3, #7
0000089e:   cmp     r2, r3
000008a0:   bls.n   0x85c <transferToFlash+20>
215       }
0 Kudos
Reply
3 Replies

746 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Mon Jun 23 01:39:37 MST 2014
Aaron,

if you write:

toAddress += 0x1000;

and toAddress is a "long" pointer, you instruct the compiler to do:

toAddress = toAddress + (0x1000 * sizeof(long)).

in words: "advance the pointer to the 0x1000th data item".

regards
Wolfgang
0 Kudos
Reply

746 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alager on Sun Jun 22 22:15:09 MST 2014
Doh!   :bigsmile:

Thanks capiman!

Aaron
0 Kudos
Reply

746 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sun Jun 22 21:52:46 MST 2014
Try changing

unsigned long * fromAddress = ...

to

unsigned char * fromAddress = ...

0 Kudos
Reply