Namespaces
Variants
Actions

C++ keyword: asm

From cppreference.com
< cpp‎ | keyword
 
 
C++ language
General topics
Conditional execution statements
Iteration statements (loops)
Jump statements
Exceptions
Namespaces
Types
Specifiers
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
Casts
Memory allocation
Class-specific function properties
Special member functions
Miscellaneous
 
Keywords
Identifiers with special meaning
(C++11)
(C++20)
(C++20)
(C++11)
(C++26)
(C++26)
 

[edit] Usage

[edit] 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.

Run this code
#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:

Hello, world!
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/keyword/asm&oldid=176160"

AltStyle によって変換されたページ (->オリジナル) /