hello:
one small question regarding use of ARM inline assembly code in a C file that has been compiled for Thumb mode.
is it possible to use ARM assembly code from within a C file that has been compiled for Thumb and Thumb interworking?
how this is done is described on this page:
i have a C file that has been compiled for Thumb mode. in it, i am using ARM inline assembly code. apparently, GCC issues no error message but forcibly converts the ARM code into Thumb code.
i think that GCC requires an entire file to be in either Thumb mode or ARM mode, but i am not sure. is that true?
the C code that is compiled into Thumb is:
void function_f( void ) { asm volatile ( ".align \n\t" ".arm \n\t" "mrs r0, cpsr \n\t" "msr cpsr_c, r0 \n\t" "pop { r0 }" ); }
the C code is compiled with: arm-elf-gcc -mlittle-endian -mcpu=arm7tdmi -march=armv4t \ -mthumb-interwork -mthumb -mno-tpcs-frame .....
here is the generated code:
00008194 : 8194: b580 push {r7, lr} 8196: af02 add r7, sp, #8 8198: 0000 lsls r0, r0, #0 819a: e10f b.n 83bc 819c: f000 e121 blx 4083e0 81a0: 0001 lsls r1, r0, #0 81a2: e8bd 46bd ldmia.w sp!, {r0, r2, r3, r4, r5, r7, r9, sl, lr} 81a6: b082 sub sp, #8 81a8: bc80 pop {r7} 81aa: bc01 pop {r0} 81ac: 4700 bx r0in the inline assembly code, if i do not use ".arm", i get compiler errors.
is it possible to use ARM assembly code from within a C file that has been compiled for Thumb and Thumb interworking?
Aaron
Makefile
--------
CC = arm-elf-gcc TARGET_ARCH = -mlittle-endian -mcpu=arm7tdmi -march=armv4t TARGET_ARCH += -mthumb -mno-tpcs-frame -mthumb-interwork
all: test arm-elf-objdump -S -D test > test.lst
clean: rm -f test test.o function.o
C CODE
------
void function_f( void ) { asm volatile ( ".align \n\t" ".arm \n\t" "mrs r0, cpsr \n\t" "msr cpsr_c, r0 \n\t" "pop { r0 }" ); }
int main( void ) { function_f(); return 0; }