我正在使用为sam7s处理器编译的gcc 4.6.3.
我需要使用一些内联汇编:
int res;
asm volatile (" \
MRS r0,CPSR \n \
MOV %0, r0 \n \
BIC r0,r0,%1 \n \
MSR CPSR,r0 \n \
" : "=r" (res) : "r" (0xc0) : "r0" );
return res;
Run Code Online (Sandbox Code Playgroud)
由gcc翻译为(由我添加的评论):
mov r3, #192 ; load 0xc0 to r3
str r0, [sl, #56] ; preserve value of r0?
mrs r0, CPSR ; load CPSR to r0
mov r3, r0 ; save r0 to "res"; r3 overwritten!
bic r0, r0, r3 ;
msr CPSR_fc, r0 ;
Run Code Online (Sandbox Code Playgroud)
问题是代替"%0"(res)和"%1"(常数:0xc0),使用相同的寄存器"r3".因此,%1在使用之前会被覆盖,并且代码工作不正确.
问题是我如何禁止gcc使用相同的寄存器作为输入/输出操作数?