这个问题很简单。
我的代码是:
__attribute__ ((naked)) void function(int arg1, int arg2, int arg3)
{
_asm("push {r0-r6}\n"
" .... ");
if(checkSomeValue(arg3))
callSomeFunction(arg1, arg2);
}asm代码与我所期望的一样:
push {r0-r6}
....
instruction of if ~ callSomefunction但是..。结果是:
str r1, [sp+0x0c]
str r2, [sp+0x08] // back up register for if~ callsomefunction statement
push {r0-r6}
...如何将asm代码放在函数的开头?
发布于 2015-05-29 08:33:51
我的方式:
__attribute__ ((naked)) void function(int arg1, int arg2, int arg3)
{
_asm("push {r0-r6}\n"
"bl calleeFunction\n"
"pop {r0-r6}\n"
"b backToOriginal\n"
);
}
void calleeFunction(int arg1, int arg2, int arg3)
{
if(checkSomeValue(arg3))
callSomeFunction(arg1, arg2);
}发布于 2019-08-29 04:03:45
现代c没有义务按任何特定的顺序采取行动。
使用C11,指令
atomic_signal_fence(memory_order_acq_rel);用于对语句强制执行顺序。在非C11编译器中,使用其他特定于编译器的命令:
gnu: __volatile__
intel: __memory_barrier()
MS: ReadWriteBarrier()https://stackoverflow.com/questions/30502936
复制相似问题