C++ キーワード: asm
From cppreference.com
[編集] 使用法
[編集] 例
この例は 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!