cortex-m0 mov instruction performed as adds

Asked by Erich Wenger

I am doing cortex-m0 assembly optimizations. Verified the problem using
arm-none-eabi-gcc (GCC) 4.7.2
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.7.3 20121207 (release) [ARM/embedded-4_7-branch revision 194305]
And the following parameters:
arm-none-eabi-as -mcpu=cortex-m0 -mthumb -g ...

I want to move some registers using:
    mov r0, r8
    mov r1, r9
    mov r7, r5

which is translated to (extracted from object dump)
 396: 4640 mov r0, r8
 398: 4649 mov r1, r9
 3a4: 1c2f adds r7, r5, #0 <-- problem

My problem is that mov does not update the carry flag, while adds does. This is a problem in my optimizations I perform.
According to the datasheets the mov instruction should be able to move from lower to lower register.

Can anybody confirm my problem?
Is this really a problem?
Is there a work-around? e.g. that I manually enter the opcode?

Thanks,
Erich

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Joey Ye
Solved:
Last query:
Last reply:
Revision history for this message
chengbin (can-finner) said :
#1

Does the assembler assembles mov into adds?

Generally this won't be a problem, since flag bit should be set before it is used.
In fact you can take advantage of this to do below optimization :

  mov r6, r5
  cmp r5, 0
  be ....

into

  adds r6, r5, 0
  be ....

Hoping this can help.

Revision history for this message
Erich Wenger (wenger-erich) said :
#2

> Does the assembler assembles mov into adds?

yes.

in my case, the "mov" instruction should not assemble to "adds"!

I do some arithmetics... "adds" (carry is set)
I need to move something. (which should not touch the carry)
I need to do a multiplication. (which does not touch the carry)
I perform an addition with carry "adcs" operation which should only be dependent on the previous addition.

Because this code is performed within the innermost loop of a loop and another loop, it actually makes a significant difference in performance.

Best regards,
Erich

Revision history for this message
Best Joey Ye (jinyun-ye) said :
#3

Erich,

Assembler problem of handling legacy ASM. Two solutions:
1. Add __asm volatile (".syntax unified"); before your inline asm, or
2. Change mov rx, ry to cpy rx, ry

- Joey

Revision history for this message
Erich Wenger (wenger-erich) said :
#4

Thanks Joey,

2. Change mov rx, ry to cpy rx, ry

works!

However, in my opinion, the default behavior of "mov" should be changed to "mov".

Cheers,
Erich

Revision history for this message
Erich Wenger (wenger-erich) said :
#5

Thanks Joey Ye, that solved my question.