Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BX LR vs MOV PC,LR

1,614 views
Skip to first unread message

Al Borowski

unread,
Apr 9, 2006, 1:12:10 AM4/9/06
to
Hi all,

I'm just starting out with the WinARM GCC toolchain for a Philips
LPC2138 microcontroller. I've hacked up one of the example projects so
it builds as follows:

==========

Assembling: crt0.S
arm-elf-gcc -c -mcpu=arm7tdmi-s -I. -x assembler-with-cpp -DROM_RUN
-Wa,-adhlns=
crt0.lst,-gdwarf-2 crt0.S -o crt0.o

Compiling C: main.c
arm-elf-gcc -c -mcpu=arm7tdmi-s -I. -gdwarf-2 -DROM_RUN -Os -Wall
-Wcast-ali
n -Wcast-qual -Wimplicit -Wpointer-arith -Wswitch -Wredundant-decls
-Wreturn-t
pe -Wshadow -Wunused -Wa,-adhlns=main.lst -I./inc -I./conf -MD -MP -MF
.dep/ma
n.o.d -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes
-Wnested-
xterns -std=gnu99 main.c -o main.o

Linking: main.elf
arm-elf-gcc -mcpu=arm7tdmi-s -I. -gdwarf-2 -DROM_RUN -Os -Wall
-Wcast-align -
Wcast-qual -Wimplicit -Wpointer-arith -Wswitch -Wredundant-decls
-Wreturn-type
-Wshadow -Wunused -Wa,-adhlns=crt0.lst -I./inc -I./conf -MD -MP -MF
.dep/main.e
lf.d crt0.o main.o --output main.elf -nostartfiles
-Wl,-Map=main.map,--c
ref -lc -lnewlib-lpc -lm -lc -lgcc -lstdc++ -TLPC2138-ROM.ld

=================

Unless I'm missing something obvious, there is no Thumb or
Thumb-Interworking support here. So why do my functions return with BX
LR instead of MOV PC,LR? If both work, is one preferred over the other?
Are they the same speed?

Thanks,

Al

Karl Olsen

unread,
Apr 9, 2006, 4:25:45 AM4/9/06
to

They are the same size and the same speed (three clocks plus MAM
waitstates). I have seen that gcc 3.4 uses MOV PC,LR while gcc 4.0 uses BX
LR. I guess it doesn't really matter which one is used.

Karl Olsen

Wilco Dijkstra

unread,
Apr 10, 2006, 5:26:01 AM4/10/06
to

"Karl Olsen" <k...@nospam.post3.tele.dk> wrote in message
news:3y3_f.12929$uO3....@news.get2net.dk...
> Al Borowski <al.bo...@gmail.com> wrote:

>> Unless I'm missing something obvious, there is no Thumb or
>> Thumb-Interworking support here. So why do my functions return with BX
>> LR instead of MOV PC,LR? If both work, is one preferred over the
>> other? Are they the same speed?

On ARM7tdmi they are the same speed, but BX lr is preferred by newer
CPUs and so runs faster.

> They are the same size and the same speed (three clocks plus MAM
> waitstates). I have seen that gcc 3.4 uses MOV PC,LR while gcc 4.0 uses
> BX
> LR. I guess it doesn't really matter which one is used.

BX LR is the official return instruction defined by the EABI and is
used by default by all conforming compilers, even on CPUs that
don't support BX (linker technology then translates BX back into
MOV pc,reg as necessary).

The reason is that using BX makes any piece of code trivially
interworking in architecture 5 and higher, while MOV pc,lr doesn't
interwork. So using it now avoids having to convert assembly code
in the future.

Wilco


0 new messages