Note that while this example works well with GCC/Clang on x86_64 platform under Linux, it's not guaranteed elsewhere as asm declaration is conditionally-supported and(since C++11) implementation defined.
#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 ); }
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4