C++ Schlüsselwort: asm
Von cppreference.com
[bearbeiten] Verwendung
[bearbeiten] Beispiel
Beachten Sie, dass dieses Beispiel unter GCC/Clang auf der x86_64-Plattform unter Linux gut funktioniert, aber nicht garantiert woanders, da die asm-Deklaration bedingt unterstützt und(seit C++11) implementierungsabhängig ist.
Führen Sie diesen Code aus
#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 ); }
Ausgabe
Hello, world!