Strange __asm code.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Strange __asm code.

782件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Mon Jun 07 06:47:42 MST 2010
[FONT=Courier New]I get some weird code coming from the inline assembler. [/FONT]
[FONT=Courier New]I have the following source;[/FONT]


[FONT=Courier New][B][COLOR=#7f0055][COLOR=#7f0055]#define [/COLOR][/COLOR][/B]DOUBLE_TOGGLE [B][COLOR=#7f0055][COLOR=#7f0055]__asm[/COLOR][/COLOR][/B]( \[/FONT]
[FONT=Courier New][COLOR=#2a00ff][COLOR=#2a00ff]"[U]mov[/U] %0, %[on_dly]\n\t"[/COLOR][/COLOR]\ [/FONT]
[LEFT][FONT=Courier New][COLOR=#2a00ff][COLOR=#2a00ff]"[U]mov[/U] %1, %[mux_addr]\n\t"[/COLOR][/COLOR]\[/FONT][/LEFT]
[FONT=Courier New][COLOR=#2a00ff][COLOR=#2a00ff]"[U]mov[/U] %2, %[bit_pat]\n\t"[/COLOR][/COLOR]\[/FONT]
[FONT=Courier New][COLOR=#2a00ff][COLOR=#2a00ff]"[U]mov[/U] %3, %[off_dly]\n\t"[/COLOR][/COLOR]\[/FONT]
[FONT=Courier New][COLOR=#2a00ff][COLOR=#2a00ff]"[U]str[/U] %2, [%1, #0]\n\t"[/COLOR][/COLOR] \[/FONT]

[LEFT][FONT=Courier New]...[/FONT][/LEFT]

[FONT=Courier New]The resulting code is; [/FONT]
[LEFT][FONT=Courier New]ldr r3, [pc, #92] (0x544 <dly_428+20>)[/FONT]
[FONT=Courier New]ldr r0, [r4, #0][/FONT]
[FONT=Courier New]ldr r1, [r3, #12][/FONT]
[FONT=Courier New]ldr r3, [pc, #88] (0x548 <dly_428+24>)[/FONT]
[FONT=Courier New]ldr r2, [r3, #0][/FONT][/LEFT]
[FONT=Courier New]ldr r3, [pc, #88] (0x54c <dly_428+28>)[/FONT]
[FONT=Courier New]adds r0, r0, #0[/FONT]
[FONT=Courier New]adds r3, r3, #0[/FONT]
[FONT=Courier New]adds r1, r1, #0[/FONT]
[FONT=Courier New]adds r2, r2, #0[/FONT]
[FONT=Courier New]str r1, [r3, #0][/FONT]

[FONT=Courier New]The MOV opcodes get translated to LDR which is OK. The loaded values are correct. [/FONT]
[FONT=Courier New]The STR opcode is unchanged. However what are the ADDS opcodes for?[/FONT]
[SIZE=2][FONT=Courier New][SIZE=3]They serve to test the incoming values but are not needed. [/SIZE][/FONT]
[FONT=Courier New][SIZE=3]I am trying to save every machine cycle and this is just a waste. [/SIZE][/FONT]
[FONT=Courier New][SIZE=3]Is there some way that I can eliminate them?[/SIZE][/FONT]


(I can't explain the odd formatting of this message, there must be some invisible char messing things up!)






[/SIZE]
0 件の賞賛
返信
4 返答(返信)

769件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Jun 09 01:37:11 MST 2010

Quote: micrio

[FONT=Courier New]The MOV opcodes get translated to LDR which is  OK. The loaded values are correct. [/FONT]
[FONT=Courier New]The STR opcode is unchanged. However what are  the ADDS opcodes for?[/FONT]



Without a buildable example (and info on which MCU you are using), I imagine that the compiler considers that the MOV is actually a MOVS (which sets the flags). Thus as an LDR doesn't set the flags, the compiler has to add in an instruction which will.


Quote: micrio
I have changed my code but still have (different) problems.
When I do inline assembly I want to write the code and have
in inserted in the routine. I don't want the compiler to fool
with it. I want the opcodes inserted as I wrote them.
I don't want the compiler to "optimize" it. If I wanted
optimization I would it write in C.

Do I need to put this in a different source file and set the optimization
parameter to -O0?


If you write assembler within your C source, then yes, you will see some optimisation.

The gcc docs give more information on this, and the following document is also quite useful:
http://www.ethernut.de/en/documents/arm-inline-asm.html
[though note that IIRC all the examples given are ARM code, rather than Thumb/Thumb2]

If you still have problems with what the compiler does, then perhaps you should consider writing an actual assembler file. There are some previous forum posts on doing this. Google something like '[I]assembly site:knowledgebase.nxp.com[/I]' to find them.

If you want further help via the forum, please post a buildable example (and make sure you include build options, especially the target MCU).

Regards,
CodeRedSupport
0 件の賞賛
返信

769件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by domen on Mon Jun 07 10:19:52 MST 2010
Interesting.
Compiler name and version?

And please a whole chuck of asm code, so if someone cares enough he can try to compile it himself.
0 件の賞賛
返信

769件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by domen on Mon Jun 07 10:19:22 MST 2010
Interesting.
Compiler name and version?

And please a whole chuck of asm code, so if someone cares enough he can try to compile it himself.
0 件の賞賛
返信

769件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micrio on Mon Jun 07 09:16:36 MST 2010
I have changed my code but still have (different) problems.
When I do inline assembly I want to write the code and have
in inserted in the routine. I don't want the compiler to fool
with it. I want the opcodes inserted as I wrote them.
I don't want the compiler to "optimize" it. If I wanted
optimization I would it write in C.

Do I need to put this in a different source file and set the optimization
parameter to -O0?
0 件の賞賛
返信