# C++ keyword: asm

> C++ Atlas: `cppatlas.com/w/cpp/keyword/asm` | Source: https://en.cppreference.com/w/cpp/keyword/asm | Domain: Keywords | Standards: C++11

## Official Specification Summary (cppreference)

### Usage

- Declaration of an inline assembly block

### Example

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.

```cpp
#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:

```text
Hello, world!
```

---
Attribution: content from https://en.cppreference.com/w/cpp/keyword/asm (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.