名前空間
変種
操作

C++ キーワード: asm

From cppreference.com
 
 
C++言語
全般
フロー制御
条件実行文
if
繰り返し文 (ループ)
for
範囲for (C++11)
ジャンプ文
関数
関数宣言
ラムダ式
inline指定子
動的例外仕様 (C++17まで*)
noexcept指定子 (C++11)
例外
名前空間
指定子
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点数
文字 - 文字列 - nullptr (C++11)
ユーザー定義 (C++11)
ユーティリティ
属性 (C++11)
typedef宣言
型エイリアス宣言 (C++11)
キャスト
メモリ確保
クラス
クラス固有の関数プロパティ
explicit (C++11)
static

特殊メンバ関数
テンプレート
その他
 
 

[編集] 使用法

[編集]

この例は 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!
English 日本語 中文(简体) 中文(繁體)