gpt4 book ai didi

c - 我不明白 C 中的这个扩展汇编内联代码

转载 作者:太空狗 更新时间:2023-10-29 15:08:10 25 4
gpt4 key购买 nike

这是一个使用扩展汇编代码的 C 函数:

static inline uint
xchg(volatile uint *addr, uint newval)
{
uint result;
asm volatile("lock; xchgl %0, %1" :
"+m" (*addr), "=a" (result) :
"1" (newval) :
"cc");
return result;
}

我读了this codeproject link了解如何在 C 代码中使用扩展程序集,但我对这段代码感到困惑。我不明白这段代码中的某些内容:
1) (newval) 在哪里用作汇编代码的输入? (%0 是指 (*addr)%1 是指 (result) 对吧? "1"(newval) 从未在代码中使用过(我们从未在代码中看到 %2)。或者我错了?)
2) 输入操作数中 "1"(newval) 中的 "1" 是什么?
3) "+m" 符号在 "+m"(*addr) 中是什么意思?

最佳答案

你所有关于GCC asm的问题的答案都可以来自6.41 Assembler Instructions with C Expression Operands6.42 Constraints for asm Operands .

关于c - 我不明白 C 中的这个扩展汇编内联代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20945929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com