{"id":8512,"date":"2024-12-24T18:45:26","date_gmt":"2024-12-24T09:45:26","guid":{"rendered":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=8512"},"modified":"2024-12-24T18:45:26","modified_gmt":"2024-12-24T09:45:26","slug":"gas-gnu-assembler-%e3%81%ae%e3%83%8d%e3%82%b9%e3%83%88%e3%81%97%e3%81%9f%e3%83%9e%e3%82%af%e3%83%ad%e5%ae%9a%e7%be%a9%e3%81%ae%e4%b8%ad%e3%81%a7-%e3%82%92%e4%bd%bf%e3%81%86%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/umezawa.dyndns.info\/wordpress\/?p=8512","title":{"rendered":"GAS (GNU assembler) \u306e\u30cd\u30b9\u30c8\u3057\u305f\u30de\u30af\u30ed\u5b9a\u7fa9\u306e\u4e2d\u3067 \\() \u3092\u4f7f\u3046\u65b9\u6cd5"},"content":{"rendered":"<p>GAS \u306e\u30de\u30af\u30ed\u5b9a\u7fa9\u306e\u4e2d\u3067\u3001\u30de\u30af\u30ed\u5f15\u6570\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\uff09\u306e\u5f8c\u308d\u306b\u6587\u5b57\u3092\u7d50\u5408\u3057\u305f\u3044\u5834\u5408\u3001\u5f15\u6570\u540d\u3068\u5f8c\u308d\u306e\u6587\u5b57\u3068\u304c\u304f\u3063\u3064\u304b\u306a\u3044\u3088\u3046\u306b\u5883\u754c\u3092\u660e\u793a\u3059\u308b\u305f\u3081\u306b\u306f <code>\\()<\/code> \u3092\u4f7f\u3048\u3001\u3068<a href=\"https:\/\/sourceware.org\/binutils\/docs\/as\/Macro.html\">\u30de\u30cb\u30e5\u30a2\u30eb\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3059<\/a>\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u5358\u7d14\u306a\u30de\u30af\u30ed\u5b9a\u7fa9\u306a\u3089\u3053\u308c\u3067\u3044\u3044\u3093\u3067\u3059\u304c\u3001\u30cd\u30b9\u30c8\u3057\u305f\u5b9a\u7fa9\u3060\u3068\u5916\u5074\u306e\u5b9a\u7fa9\u3092\u5c55\u958b\u3059\u308b\u6642\u306b <code>\\()<\/code> \u304c\u89e3\u91c8\u3055\u308c\u3066\u6d88\u6ec5\u3059\u308b\u306e\u3067\u3001\u3046\u307e\u304f\u50cd\u304d\u307e\u305b\u3093\u3002<\/p>\n<blockquote>\n<pre>\r\n[umezawa@devubuntu:pts\/0 ~]$ cat gas_nested_macro_expansion.cc\r\nvoid foo()\r\n{\r\n        asm volatile (\r\n        R\"(\r\n        nop\r\n        .macro MACRO_OUTER x\r\n        .macro MACRO_INNER y\r\n        cmp %al, %r\\x\\()b\r\n        cmp %al, %r\\y<strong>\\()<\/strong>b\r\n        .endm\r\n        MACRO_INNER 8\r\n        .endm\r\n        MACRO_OUTER 9\r\n        nop\r\n        )\");\r\n}\r\n[umezawa@devubuntu:pts\/0 ~]$ g++ -c gas_nested_macro_expansion.cc\r\ngas_nested_macro_expansion.cc: Assembler messages:\r\ngas_nested_macro_expansion.cc:12: Error: invalid character '\\' in operand 2\r\n[umezawa@devubuntu:pts\/0 ~]$ clang++ -c gas_nested_macro_expansion.cc\r\n<instantiation>:2:11: error: invalid register name\r\n        cmp %al, %r\\yb\r\n                 ^\r\n<instantiation>:5:2: note: while in macro instantiation\r\n        MACRO_INNER 8\r\n        ^\r\ngas_nested_macro_expansion.cc:13:1: note: while in macro instantiation\r\n        MACRO_OUTER 9\r\n^\r\n<inline asm>:10:2: note: instantiated into assembly here\r\n        MACRO_OUTER 9\r\n        ^\r\n1 error generated.\r\n<\/pre>\n<\/blockquote>\n<p>\u6570\u5e74\u524d\u306b\u3053\u308c\u306b\u56f0\u3063\u3066\u305f\u3093\u3067\u3059\u304c\u3001\u6700\u8fd1 <code>\\(\\())<\/code> \u3068\u66f8\u3051\u3070\u56de\u907f\u3067\u304d\u308b\u3053\u3068\u306b\u6c17\u3065\u304d\u307e\u3057\u305f\u3002<\/p>\n<blockquote>\n<pre>\r\n[umezawa@devubuntu:pts\/0 ~]$ !cat\r\nvoid foo()\r\n{\r\n        asm volatile (\r\n        R\"(\r\n        nop\r\n        .macro MACRO_OUTER x\r\n        .macro MACRO_INNER y\r\n        cmp %al, %r\\x<strong>\\(\\())<\/strong>b\r\n        cmp %al, %r\\y<strong>\\(\\())<\/strong>b\r\n        .endm\r\n        MACRO_INNER 8\r\n        .endm\r\n        MACRO_OUTER 9\r\n        nop\r\n        )\");\r\n}\r\n[umezawa@devubuntu:pts\/0 ~]$ g++ -c gas_nested_macro_expansion.cc\r\n[umezawa@devubuntu:pts\/0 ~]$ objdump -d gas_nested_macro_expansion.o\r\n\r\ngas_nested_macro_expansion.o:     file format elf64-x86-64\r\n\r\n\r\nDisassembly of section .text:\r\n\r\n0000000000000000 <_Z3foov>:\r\n   0:   f3 0f 1e fa             endbr64\r\n   4:   55                      push   %rbp\r\n   5:   48 89 e5                mov    %rsp,%rbp\r\n   8:   90                      nop\r\n   9:   41 38 c1                cmp    %al,%r9b\r\n   c:   41 38 c0                cmp    %al,%r8b\r\n   f:   90                      nop\r\n  10:   90                      nop\r\n  11:   5d                      pop    %rbp\r\n  12:   c3                      ret\r\n<\/pre>\n<\/blockquote>\n<p>\u4e0a\u3067\u306f <code>x<\/code> \u306e\u65b9\u3067\u3082 <code>\\(\\())<\/code> \u3068\u66f8\u3044\u3066\u3044\u307e\u3059\u304c\u3001<code>x<\/code> \u3092\u5c55\u958b\u3059\u308b\u306e\u306f\u5916\u5074\u306e\u30de\u30af\u30ed\u306e\u5c55\u958b\u6642\u306a\u306e\u3067\u3001<code>\\()<\/code> \u3068\u66f8\u3044\u3066\u3082\u671f\u5f85\u901a\u308a\u306e\u52d5\u4f5c\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GAS \u306e\u30de\u30af\u30ed\u5b9a\u7fa9\u306e\u4e2d\u3067\u3001\u30de\u30af\u30ed\u5f15\u6570\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\uff09\u306e\u5f8c\u308d\u306b\u6587\u5b57\u3092\u7d50\u5408\u3057\u305f\u3044\u5834\u5408\u3001\u5f15\u6570\u540d\u3068\u5f8c\u308d\u306e\u6587\u5b57\u3068\u304c\u304f\u3063\u3064\u304b\u306a\u3044\u3088\u3046\u306b\u5883\u754c\u3092\u660e\u793a\u3059\u308b\u305f\u3081\u306b\u306f \\() \u3092\u4f7f\u3048\u3001\u3068\u30de\u30cb\u30e5\u30a2\u30eb\u306b\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[],"class_list":["post-8512","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8512"}],"version-history":[{"count":5,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8512\/revisions"}],"predecessor-version":[{"id":8537,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/8512\/revisions\/8537"}],"wp:attachment":[{"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8512"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/umezawa.dyndns.info\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}