http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59593
Bug ID: 59593 Summary: [arm big-endian] using "ldrh" access a immediate which stored in a memory by word Product: gcc Version: 4.7.1 Status: UNCONFIRMED Severity: critical Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: spf_zju at 126 dot com the C code like this: short int a = 1; int test() { return 922 * a; } compile the C code : arm-eabi-gcc -mbig-endian -O2 -S bar.c -o bar.s the bar.s like this : movw r3, #:lower16:.LANCHOR0 movt r3, #:upper16:.LANCHOR0 ldrh r0, [r3,#0] ldrh r3, .L2 smulbb r0, r0, r3 bx lr .L3: .align 2 .L2: .word 922 The immediate 922 is stored in .L2, in arm big-endian mode ,the memory of .L2 is like this 0x0000039a, so when executing this "ldrh r0, [r3,#0]", the r0 is zero,so the result is wrong . also see the disassembly of bar.o : <test>: 0: e3003000 movw r3, #0 4: e3403000 movt r3, #0 8: e1d300b0 ldrh r0,[r3] c: e1df30b4 ldrh r3,[pc,#4] ;18 10:e1b00380 smulbb r0,r0,r3 14:e12fff1e bx lr 18:0000039a muleq r0,sl,r3 So the return value of the function test is zero. it is wrong .