C++ 关键字: asm
来自 cppreference.cn
[编辑] 用法
[编辑] 示例
请注意,虽然此示例在 Linux 下的 x86_64 平台上使用 GCC/Clang 可以很好地工作,但在其他地方不能保证,因为 asm 声明是 有条件支持的,并且(自 C++11 起) 实现定义的。
运行此代码
#include <cstring> int main() noexcept { const char* const c_string = "Hello, world!\n"; asm (R"( movq $1, %%rax # syscall number for sys_write movq $1, %%rdi # file descriptor 1 (stdout) movq %0, %%rsi # pointer to the c‐string movq %1, %%rdx # length of the c‐string syscall # invokes an OS system-call handler )" : // no output operands : "r"(c_string), // input: pointer to the c‐string "r"(std::strlen(c_string)) // input: size of the c‐string : "%rax", "%rdi", "%rsi", "%rdx" // clobbered registers ); }
输出
Hello, world!