Microchip
直播中

宁晓蕾

7年用户 135经验值
私信 关注
[问答]

在asm语句中使用volatile,ASM和γ-ASMY之间有什么区别吗?

嗨,在研究谷歌之后,在XC32指南上,我放弃并问:ASM(“…”)和ASM易失性(“…”)之间的区别是什么?而且,ASM和γ-ASMY之间有什么区别吗?谢谢你,M.R.

以上来自于百度翻译


      以下为原文

     
Hi,
after research on Google and on the XC32 Guide, I give up and ask here.

What is the difference between asm("...") and asm volatile ("...") ?

And, is there any difference between asm and __asm__ ?

Thank you.

M.R.

回帖(7)

李维兴

2018-9-26 16:48:50
没有区别。易失性限定符是可选的,并且没有影响,因为所有的ASM块都是隐式的易失性。当编写可以用ANSI(或X-32中的-FNOM ASM)编译的代码和各种STD选项时,使用Y-asASMY代替ASM,其中关键字ASM、内联和Type不被识别为关键字,因此代码可以使用这些词作为标识符。

以上来自于百度翻译


      以下为原文

   
No difference.  The volatile qualifier is optional and has no effect, as all asm blocks are implicitly volatile.
 

When writing code that can be compiled with -ansi (or -fno-asm in XC32) and the various -std options, use __asm__ instead of asm, where the keywords asm, inline, and typeof are not recognized as keywords, so that code can use these words as identifiers.
举报

李铭鑫

2018-9-26 17:02:29
嗨,上面的一些问题在GCC文档中得到回答:HTTPS://Gcc.GNUGOR/ONLIDEOCS/GCC/ExtDeD-ASM.HTMLASM和Y-AASMYI以相同的方式工作,但是这两种形式都是标准化C语言定义的扩展。因此,在严格解释C语言规则时,ASM应该是变量的名称,或者ASM(…)可以调用的函数的名称。如果使用更严格的语言标准选项编译,如-ANSI或-STD=……,它们仍然会被接受。在编译器命令行中。迈西尔

以上来自于百度翻译


      以下为原文

    Hi,
Some of the questions above are answered in GCC documentation:
https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
 
asm and  __asm__  work the same way,
but both forms are extensions to the standardized C language definitions.
In C language, there is a  set of keywords that have defined meaning in the language, and asm is not one of those. 
So in strict interpretation of C language rules,   asm  should be the name of a variable, or asm(...) the name of a function that may be called.
 
Keywords with double underscore:  __something   or  __something__
is a way of using features of the compiler, without breaking language rules.
They will still be accepted if compiled with more strict language standard options,
like -ansi  or -std=...     in compiler command line.
 
   Mysil
举报

李子跃

2018-9-26 17:14:28
没有区别。易失性限定符是可选的,没有影响,因为所有的ASM块都隐含地是不稳定的。不正确。ASM(“…”)语句的内容在优化和最终汇编之前只与编译器*的输出对齐。易失性被用来提示优化代码可能有副作用,以防止它被优化。注意,除非使用NoeReald/RealDead汇编器指令,您的优化优化的ASM代码*将被优化器所困扰。

以上来自于百度翻译


      以下为原文

   
No difference.  The volatile qualifier is optional and has no effect, as all asm blocks are implicitly volatile.

Not correct.
The contents of the asm("...") statement are pretty much just inlined with the output of the compiler *before optimisation and final assembly*. The volatile is used to hint to the optimiser that the code may have side effects, to prevent it being optimised away.
Note that unless you use the .noreorder/.reorder assembler directives, your nicely optimised asm code *will* be messed with by the optimiser.
举报

李维兴

2018-9-26 17:29:18
你说得对。当我张贴时,我在想,因为我似乎记得在这里阅读优化器可以弄乱汇编代码。

以上来自于百度翻译


      以下为原文

   
You're correct. I was thinking of that when I posted, as I seem to recall reading here that the optimizer can mess with the assembly code.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分