【问题标题】:How can use asm() with a const char* instead of a string literal?如何将 asm() 与 const char* 一起使用而不是字符串文字?
【发布时间】:2021-09-20 08:20:34
【问题描述】:

如果我这样做:

const char *str = "some assembly instructions";
asm(str);

CLion 会说“'asm' 中的预期字符串文字”

【问题讨论】:

标签: c assembly inline-assembly string-literals


【解决方案1】:

asm 不是在运行时调用的普通 C 函数,而是在编译时发出您指定的汇编代码的特殊指令。 asm 需要在编译时知道汇编指令,这只有在参数是字符串文字时才有可能:

正确:

asm("some instruction");   // "some instruction" is known at compile time

不正确:

asm(str);    // at compile time it is potentially not known where
             // str points to

结论:您不能将字符串文字以外的任何内容传递给asm

【讨论】:

    猜你喜欢
    • 2020-01-03
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多