{"id":1378,"date":"2019-10-13T15:15:35","date_gmt":"2019-10-13T07:15:35","guid":{"rendered":"https:\/\/xbtzone.com\/blog\/?p=1378"},"modified":"2020-05-20T11:49:44","modified_gmt":"2020-05-20T03:49:44","slug":"gcc-assembler","status":"publish","type":"post","link":"https:\/\/xbtzone.com\/blog\/gcc-assembler\/","title":{"rendered":"Day 146 GCC \u5185\u8054\u6c47\u7f16\u4e0e Intel \u8bed\u6cd5\u8fc1\u79fb"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u524d\u8a00<\/h2>\n\n\n\n<p>\u524d\u6bb5\u65f6\u95f4\u548c\u5728\u540c\u5b66\u9662\u91cc\u7814\u7a76\u5d4c\u5165\u5f0f\u65b9\u5411\u7684\u4e00\u4f4d\u540c\u5b66\u4ecb\u7ecd\u4e86\u4e00\u4e0b x86 \u6c47\u7f16\uff0c\u53e6\u5916\u8fd8\u544a\u8bc9\u4ed6\u80fd\u5728 C \u8bed\u8a00\u4ee3\u7801\u91cc\u76f4\u63a5\u5d4c\u5165\u5185\u8054\u6c47\u7f16\u4ee3\u7801\uff0c\u4f46\u662f\u4e00\u4e0a\u624b\u5c31\u906d\u9047\u4e86\u5c34\u5c2c\u3002(\u2212_\u2212\uff03)<\/p>\n\n\n\n<p>\u6211\u8fd8\u5728\u7528 Windows \u505a\u5f00\u53d1\u7684\u65f6\u5019\u5e38\u7528\u7684\u662f Visual Studio\uff0cVisual Studio \u6709\u7740\u5fae\u8f6f\u81ea\u5bb6\u7684\u4e00\u5957 C \u8bed\u8a00\u7f16\u8bd1\u5668 VC Compiler\uff0c\u5c3d\u7ba1\u5fae\u8f6f\u5728\u91cc\u9762\u52a0\u4e86\u4e00\u5806\u65e0\u5398\u5934\u8bbe\u8ba1\uff08\u6bd4\u5982 sprintf \u51fd\u6570\u83ab\u540d\u5176\u5999\u8981\u52a0\u4e2a _s \u624d\u7b97\u300e\u5b89\u5168\u300f\uff09\u3002\u5728\u8fd9\u91cc\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 asm \u6216\u8005 __asm \u5173\u952e\u5b57\u5d4c\u5165\u5185\u8054\u6c47\u7f16\uff0c\u6bd4\u5982\u4e0b\u9762\u7684\u4ee3\u7801\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int counter = 0;\n__asm {\n\tmov eax, counter\n\tinc eax\n\tmov counter, eax\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u5c06\u4e00\u6bb5\u5185\u8054\u6c47\u7f16\u4ee3\u7801\u76f4\u63a5\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u5f00\u53d1\u73af\u5883 CLion \u4e0b\uff0c\u53d1\u73b0\u7f16\u8bd1\u5931\u8d25\u3002\u521a\u8fd8\u548c\u540c\u5b66\u4fe1\u8a93\u65e6\u65e6\u5730\u8bf4\u80fd\u5728 C \u8bed\u8a00\u91cc\u9762\u5199\u6c47\u7f16\u7684\uff0c\u8fd9\u4e0b\u5c34\u5c2c\u7684&#8230;&#8230;<\/p>\n\n\n\n<p>\u8fc7\u4e00\u6bb5\u65f6\u95f4\uff0c\u67e5\u4e86\u4e00\u4e9b\u8d44\u6599\uff0c\u6076\u8865\u4e00\u6ce2\u6c47\u7f16\u77e5\u8bc6\uff0c\u4e5f\u7b97\u662f\u5f00\u4e86\u773c\u754c\u3002<\/p>\n\n\n\n<p>CLion \u9ed8\u8ba4\u4f7f\u7528\u7684\u662f GCC \u7f16\u8bd1\u5668\uff0cGCC \u7f16\u8bd1\u5668\u540c\u6837\u652f\u6301\u5185\u8054\u6c47\u7f16\uff0c\u4f46\u662f\u8bed\u6cd5\u4e0e VC \u7f16\u8bd1\u5668\u5e76\u4e0d\u4e00\u6837\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. GCC \u7684\u6c47\u7f16\u8bed\u6cd5<\/strong><\/h2>\n\n\n\n<p>VC \u7f16\u8bd1\u5668\u4f7f\u7528\u7684\u6c47\u7f16\u8bed\u6cd5\u662f Intel \u8bed\u6cd5\uff0c\u4e0e VC \u7f16\u8bd1\u5668\u4e0d\u540c\uff0cGCC \u7f16\u8bd1\u5668\u4f7f\u7528\u7684\u6c47\u7f16\u8bed\u6cd5\u662f <strong>AT&amp;T\/UNIX<\/strong> \u8bed\u6cd5\uff0c\u6bd5\u7adf GCC \u662f UNIX \u73af\u5883\u4e0b\u7684 C \u8bed\u8a00\u7f16\u8bd1\u5668\u3002<\/p>\n\n\n\n<p>\u81f3\u4e8e\u4e3a\u4ec0\u4e48 VC \u7f16\u8bd1\u5668\u4f1a\u4f7f\u7528 Intel \u6c47\u7f16\u8bed\u6cd5\uff0c\u53ef\u80fd\u548c\u5f53\u5e74\u5fae\u8f6f\u548c\u82f1\u7279\u5c14\u7684\u5546\u4e1a\u5408\u4f5c\u6709\u5173\uff0c\u6709\u5174\u8da3\u7684\u8bfb\u8005\u53ef\u4ee5\u53bb\u4e86\u89e3\u4e0b <strong>Wintel Dynasty<\/strong> \uff08Wintel \u671d\u4ee3\uff09\u7684\u5386\u53f2\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u8fd9\u4e2a <strong>AT&amp;T<\/strong> \u53c8\u662f\u4f55\u65b9\u795e\u5723\u5462\uff1f\u5b83\u662f\u7f8e\u56fd\u7684\u4e00\u5bb6\u5f88\u77e5\u540d\u7684\u901a\u4fe1\u516c\u53f8\uff0c\u65d7\u4e0b\u5305\u542b\u53e6\u5916\u51e0\u4e2a\u6709\u540d\u5b50\u516c\u53f8\u6bd4\u5982 AOL \uff08American Online\uff0c\u7f8e\u56fd\u5728\u7ebf\uff0c\u5c31\u662f\u90a3\u4e2a\u505a\u4e86 AIM \u8f6f\u4ef6\u7684\u516c\u53f8\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u6e90-\u76ee\u6807\u7684\u5bfb\u5740\u987a\u5e8f<\/h3>\n\n\n\n<ul><li>Intel\uff1aOp-code dst src \uff08\u5982 mov eax, ecx\uff0c\u5c06 ecx \u8d4b\u503c\u7ed9 eax\uff09<\/li><li>GCC\uff1aOp-code src dst \uff08\u5982 movl %ecx, %eax\uff0c\u5c06 ecx \u8d4b\u503c\u7ed9 eax\uff09<\/li><\/ul>\n\n\n\n<p>\u8fd9\u540c\u65f6\u4e5f\u662f Intel \u8bed\u6cd5\u4e0e AT&amp;T \u8bed\u6cd5\u6700\u5927\u7684\u4e0d\u540c\uff0c\u5bfb\u5740\u987a\u5e8f\u662f\u76f8\u53cd\u7684\uff0c\u5728\u5b9e\u9645\u8fc1\u79fb\u8fc7\u7a0b\u4e2d\u7ecf\u5e38\u4f1a\u5728\u8fd9\u91cc\u72af\u9519\u8bef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u5bc4\u5b58\u5668\u547d\u540d\u65b9\u5f0f<\/h3>\n\n\n\n<ul><li>Intel\uff1aeax<\/li><li>GCC\uff1a%eax<\/li><\/ul>\n\n\n\n<p>\u6ce8\u610f\u5bc4\u5b58\u5668\u8981\u4ee5 <strong>%<\/strong> \u4f5c\u4e3a\u524d\u7f00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 \u7acb\u5373\u5bfb\u5740\u578b\u64cd\u4f5c\u6570<\/h3>\n\n\n\n<ul><li>Intel\uff1a\u5341\u8fdb\u5236\u5e38\u6570\u53ef\u76f4\u63a5\u7528\u6570\u503c\u8868\u793a\u3002\u5341\u516d\u8fdb\u5236\u5e38\u6570\u4e00\u822c\u7528 h \u4f5c\u4e3a\u540e\u7f00\uff0c\u4ee5\u8868\u660e\u8fd9\u662f\u4e2a\u5341\u516d\u8fdb\u5236\u5e38\u6570\uff0c\u6709\u65f6\u4e5f\u53ef\u4ee5 0x \u4e3a\u524d\u7f00\u8868\u793a\uff0c\u6bd4\u5982 11h \u548c 0x11\u3002<\/li><li>GCC\uff1a\u4efb\u4f55\u7acb\u5373\u6570\u90fd\u4ee5 $ \u5f00\u5934\uff0c\u5341\u516d\u8fdb\u5236\u6570\u8fd8\u8981\u5728\u7f8e\u5143\u7b26\u53f7\u540e\u8fb9\u52a0\u4e0a 0x \u8868\u793a\u5b83\u662f\u4e2a\u5341\u516d\u8fdb\u5236\u5e38\u6570\u3002<\/li><\/ul>\n\n\n\n<p>\u6ce8\u610f\uff0c\u5bf9\u4e8e GCC \u73af\u5883\uff0c\u8fd9\u91cc\u6240\u9002\u7528\u7684\u60c5\u51b5\u662f\u5728\u7acb\u5373\u5bfb\u5740\u65f6\u8868\u793a\u7acb\u5373\u6570\uff0c\u5f53\u6d89\u53ca\u5230\u53d8\u5740\u5bfb\u5740\u8868\u793a\u504f\u79fb\u91cf\u64cd\u4f5c\u6570\u65f6\uff0c\u4e0d\u518d\u9700\u8981\u52a0\u4e0a $ \u4f5c\u4e3a\u524d\u7f00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.4 \u64cd\u4f5c\u6570\u5927\u5c0f<\/h3>\n\n\n\n<ul><li>Intel\uff1abyte ptr\uff0cword ptr\uff0cdword ptr\uff0cqword ptr\u3002\u5206\u522b\u8868\u793a\u5b57\u8282\u3001\u53cc\u5b57\u8282\u3001\u56db\u5b57\u8282\u3001\u5341\u516d\u5b57\u8282\u3002<\/li><li>GCC\uff1a\u66f4\u4e3a\u7b80\u5316\uff0c\u4f7f\u7528 b\uff0cw\uff0cl\uff0cq \u5728\u6307\u4ee4\u7684\u540e\u7f00\u52a0\u4e0a\u5373\u53ef\u3002\u6bd4\u5982\uff1amov al, byte ptr counter =&gt; movb counter, %al<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.5 \u57fa\u5730\u5740<\/h3>\n\n\n\n<ul><li>Intel\uff1a\u57fa\u5730\u5740\u653e\u5728 [ \u3001 ] \u4e4b\u95f4\u3002<\/li><li>GCC\uff1a\u57fa\u5730\u5740\u653e\u5728 ( \u3001 ) \u4e4b\u95f4\u3002<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">1.6 \u53d8\u5740\u5bfb\u5740\u64cd\u4f5c\u6570<\/h3>\n\n\n\n<ul><li>Intel\uff1a[base + index*size + disp]\uff0c\u5982 mov eax, [ebx+esi*4-20h]<\/li><li>GCC\uff1adisp(base, index, size)\uff0c\u5982 movl -0x20(%ebx, %esi, 4), %eax<\/li><\/ul>\n\n\n\n<p>\u504f\u79fb\u91cf\u548c\u5927\u5c0f\u6570\u503c\u90fd\u4e0d\u9700\u8981 $ \u524d\u7f00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.7 \u603b\u89c8<\/h3>\n\n\n\n<table class=\"wp-block-table is-style-stripes\"><tbody><tr><td><strong>Intel<\/strong><\/td><td><strong>GCC<\/strong><\/td><\/tr><tr><td>mov eax, 1<\/td><td>movl $1, %eax<\/td><\/tr><tr><td>mov ebx, 0A2h<\/td><td>movl $0xA2, %ebx<\/td><\/tr><tr><td>int 3<\/td><td>int $3<\/td><\/tr><tr><td>mov ecx, edx<\/td><td>movl %edx, %ecx<\/td><\/tr><tr><td>mov eax, [ebx]<\/td><td>movl (%ebx), (%eax)<\/td><\/tr><tr><td>mov ebp, [esp+8]<\/td><td>movl 8(%esp), %ebp<\/td><\/tr><tr><td>mov rax, [rdx+10h]<\/td><td>movq 0x10(%rdx), %rax<\/td><\/tr><tr><td>add eax, [ebx+ecx*4h]<\/td><td>addl (%ebx, %ecx, 0x4), %eax<br><\/td><\/tr><tr><td>lea edx,[eax+ebx*4h-20h]<\/td><td>leal -0x20(%eax, %ebx, 0x4), %edx<\/td><\/tr><tr><td>inc eax<\/td><td>incl eax<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h2 class=\"wp-block-heading\">2. \u5728 C \u8bed\u8a00\u4e2d\u4f7f\u7528 GCC \u5185\u8054\u6c47\u7f16<\/h2>\n\n\n\n<p>\u4e0e VC \u7f16\u8bd1\u5668\u76f8\u4f3c\uff0c\u5728 GCC \u4e2d\u4f7f\u7528\u5185\u8054\u6c47\u7f16\u4e00\u6837\u8981\u7528\u5230 asm \u5173\u952e\u5b57\uff0c\u5f53\u7136\u4e3a\u4e86\u907f\u514d\u5173\u952e\u5b57\u6df7\u6dc6\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 __asm__ \u5173\u952e\u5b57\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>asm(\"\u4f60\u7684\u6c47\u7f16\u4ee3\u7801\")<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>asm(\"movl %ebx, %eax\")\n__asm__(\"movl $0x20, %edi\")<\/code><\/pre>\n\n\n\n<p>\u5f53\u8981\u5728\u540c\u4e00\u6761 __asm__ \u8c03\u7528\u91cc\u5d4c\u5165\u591a\u884c\u6c47\u7f16\u4ee3\u7801\u65f6\uff0c\u5e94\u4f7f\u7528 <strong>\\n\\t<\/strong> \u5206\u5272\u6bcf\u4e00\u884c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>__asm__(\"movl $0xb, %ebx\\n\\t\"\n        \"movl $0x20, %edi\\n\\t\"\n        \"nop\\n\\t\"\n        \"incl %eax\");<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. GCC \u6269\u5c55\u6c47\u7f16<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u6269\u5c55\u6c47\u7f16<\/h3>\n\n\n\n<p>GCC \u91cc\u7684\u6c47\u7f16\u6307\u4ee4\u5e76\u4e0d\u662f\u4e00\u6210\u4e0d\u53d8\u7684\u4e00\u4e32\u5b57\u7b26\u4e32\uff0c\u4f60\u53ef\u4ee5\u8fdb\u884c\u4e00\u4e9b\u6307\u5b9a\u6216\u8005\u9650\u5b9a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>asm (\"\u6c47\u7f16\u6307\u4ee4\"\n     : \u8f93\u51fa \/* \u53ef\u9009 *\/\n     : \u8f93\u5165 \/* \u53ef\u9009 *\/\n     : \u6d89\u53ca\u5230\u7684\u5bc4\u5b58\u5668 \/* \u53ef\u9009 *\/<\/code><\/pre>\n\n\n\n<p>\u7528\u4e00\u6bb5\u4ee3\u7801\u6765\u8bf4\u660e\u6269\u5c55\u6c47\u7f16\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int a=10, b;\nasm (\"movl %1, %%eax; movl %%eax, %0;\"\n    : \"=r\"(b)\n    : \"r\"(a)\n    : \"%eax\"\n    );<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5c06\u53d8\u91cf a \u7684\u503c\u8d4b\u503c\u7ed9\u53d8\u91cf b\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u5192\u53f7\u6307\u5b9a\u8f93\u51fa\u64cd\u4f5c\u6570\uff0c\u5728\u6c47\u7f16\u4ee3\u7801\u91cc\u7528 <b>%0<\/b> \u8868\u793a\uff0c\u8fd9\u91cc\u6307\u7684\u662f\u53d8\u91cf b\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e8c\u884c\u5192\u53f7\u6307\u5b9a\u8f93\u5165\u64cd\u4f5c\u6570\uff0c\u5728\u6c47\u7f16\u4ee3\u7801\u91cc\u53ef\u7528 <b>%1\u3001%2\u3001%3 &#8230;&#8230;<\/b> \u8868\u793a\uff0c\u8fd9\u91cc\u7684 <strong>%1<\/strong> \u6307\u7684\u662f<strong>\u7b2c\u4e00\u4e2a<\/strong>\u8f93\u5165\u7684\u53c2\u6570\uff1a\u53d8\u91cf a\u3002<\/p>\n\n\n\n<p>\u201cr\u201d \u7528\u4e8e\u9650\u5236\u64cd\u4f5c\u6570\uff0c\u8fd9\u91cc\u7684 r \u544a\u8bc9 GCC \u7f16\u8bd1\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u7684\u5bc4\u5b58\u5668\u6765\u5b58\u53d6\u8f93\u5165\u548c\u8f93\u51fa\u7684\u64cd\u4f5c\u6570\u3002\u8f93\u51fa\u64cd\u4f5c\u6570\u7684\u9650\u5236\u7b26\u524d\u9762\u9700\u8981\u4e00\u4e2a = \u53f7\uff0c\u8bf4\u660e\u8fd9\u4e2a\u8f93\u51fa\u64cd\u4f5c\u6570\u662f\u53ea\u5199\u7684\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e09\u884c\u5192\u53f7\u544a\u8bc9\u8fd9\u6b21\u5185\u8054\u6c47\u7f16\u54ea\u4e9b\u5bc4\u5b58\u5668\u53d7\u5230\u4e86\u5f71\u54cd\uff0c\u8fd9\u4e00\u884c\u4e00\u822c\u53ef\u4ee5\u7701\u7565\u6389\uff0c\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u203b \u4e0e\u901a\u5e38\u7684\u5185\u8054\u6c47\u7f16\u4e0d\u540c\uff0c\u5728\u4f7f\u7528\u4e86\u6269\u5c55\u6c47\u7f16\u540e\uff0c\u6c47\u7f16\u4ee3\u7801\u91cc\u7684\u5404\u4e2a\u5bc4\u5b58\u5668\u7684\u524d\u7f00\u8fd8\u8981\u53e6\u5916\u52a0\u4e0a\u4e00\u4e2a % \u7b26\u53f7\uff0c\u4ee5\u514d\u548c\u4e00\u4e9b\u53d8\u91cf\u6df7\u6dc6\uff0c\u5982 %eax =&gt; %%eax\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u201c\u4e0d\u7a33\u5b9a\u7684\u201d\u58f0\u660e<\/h3>\n\n\n\n<p>\u5728 asm \u5173\u952e\u5b57\u540e\u8fb9\u53ef\u4ee5\u52a0\u5165 volatile \uff08\u4e5f\u53ef\u4ee5\u7528 __volatile__\uff09\uff0c\u9632\u6b62\u4f60\u7684\u6c47\u7f16\u4ee3\u7801\u56e0\u4e3a\u7f16\u8bd1\u5668\u81ea\u8eab\u7684\u4ee3\u7801\u4f18\u5316\u800c\u88ab\u79fb\u52a8\u3001\u5220\u9664\u6216\u5176\u4ed6\u4efb\u4f55\u6539\u53d8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.3 \u9650\u5236\u7b26<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">3.3.1 \u5bc4\u5b58\u5668\u9650\u5236\u7b26<\/h4>\n\n\n\n<p>\u524d\u9762\u63d0\u5230\u53ef\u4ee5\u7528 r \u8868\u793a\u4f7f\u7528\u4efb\u610f\u7684\u5bc4\u5b58\u5668\uff0c\u5176\u5b9e\u6211\u4eec\u8fd8\u53ef\u4ee5\u81ea\u5df1\u6307\u5b9a\u8981\u4f7f\u7528\u5230\u7684\u5bc4\u5b58\u5668\u3002<\/p>\n\n\n\n<table class=\"wp-block-table is-style-stripes\"><tbody><tr><td>r<\/td><td>\u4efb\u4f55\u5bc4\u5b58\u5668<\/td><\/tr><tr><td>a<\/td><td>%rax, %eax, %ax, %al<\/td><\/tr><tr><td>b<\/td><td>%rbx, %ebx, %bx, %bl<\/td><\/tr><tr><td>c<\/td><td>%rcx, %ecx, %cx, %cl<\/td><\/tr><tr><td>d<\/td><td>%rdx, %edx, %dx, %dl<\/td><\/tr><tr><td>S<\/td><td>%rsi, %esi, %si<\/td><\/tr><tr><td>D<\/td><td>%rdi, %edi, %di<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h4 class=\"wp-block-heading\">3.3.2 \u5185\u5b58\u64cd\u4f5c\u6570\u9650\u5236\u7b26<\/h4>\n\n\n\n<p>\u5c3d\u7ba1\u6211\u4eec\u6709\u5bc4\u5b58\u5668\u53ef\u4ee5\u4f5c\u4e3a\u5916\u90e8\u8f93\u51fa\u8f93\u5165\u7684\u4e2d\u8f6c\uff0c\u4f46\u4ee3\u4ef7\u6709\u65f6\u662f\u7834\u574f\u5df2\u6709\u7684\u5bc4\u5b58\u5668\u5185\u5bb9\uff0c\u4e3a\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u5b58\u64cd\u4f5c\u6570\u9650\u5236\u7b26\uff0c\u76f4\u63a5\u901a\u8fc7\u5185\u5b58\u8fdb\u884c\u5bfb\u5740\uff0c\u6700\u5927\u5316\u5bfb\u5740\u6027\u80fd\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u5bc4\u5b58\u5668\uff08\u5c3d\u7ba1\u5bc4\u5b58\u5668\u5bfb\u5740\u66f4\u5feb\uff09\u3002\u8be5\u9650\u5236\u7b26\u662f\u201cm\u201d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>asm(\"sidt %0\\n\" : :\"m\"(loc));<\/code><\/pre>\n\n\n\n<p style=\"text-align:left\">\u4e0a\u8ff0\u4ee3\u7801\u901a\u8fc7\u5185\u5b58\u64cd\u4f5c\u6570\u5bfb\u5740\u628a idtr \u5bc4\u5b58\u5668\u7684\u5185\u5bb9\u50a8\u5b58\u5230\u53d8\u91cf loc\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.3.3 \u6570\u5b57\u9650\u5236\u7b26<\/h4>\n\n\n\n<p>\u5982 &#8220;0&#8221; \u8868\u793a\u5728\u6c47\u7f16\u4ee3\u7801\u4e2d\uff0c\u5f53\u524d\u8f93\u5165\u6216\u8f93\u51fa\u53c2\u6570\u7528 <strong>%0<\/strong> \u8868\u793a\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.3.4 \u5176\u4ed6\u9650\u5236\u7b26<\/h4>\n\n\n\n<p>\u9664\u4e86\u4e0a\u8ff0\u7684\u9650\u5236\u7b26\u5916\u8fd8\u6709\u5176\u4ed6\u7684\u9650\u5236\u7b26\u3002<\/p>\n\n\n\n<table class=\"wp-block-table is-style-stripes\"><tbody><tr><td>\u9650\u5236\u7b26<\/td><td>\u529f\u80fd<\/td><\/tr><tr><td>m<\/td><td>\u5185\u5b58\u64cd\u4f5c\u6570<\/td><\/tr><tr><td>o<\/td><td>\u5185\u5b58\u64cd\u4f5c\u6570\uff0c\u4ec5\u7528\u4e8e\u504f\u79fb\u91cf<\/td><\/tr><tr><td>V<\/td><td>\u5185\u5b58\u64cd\u4f5c\u6570\uff0c\u7528\u4e8e\u975e\u504f\u79fb\u91cf<\/td><\/tr><tr><td>i<\/td><td>\u7acb\u5373\u6574\u578b\u64cd\u4f5c\u6570<\/td><\/tr><tr><td>n<\/td><td>\u7acb\u5373\u6574\u578b\u64cd\u4f5c\u6570\uff0c\u5141\u8bb8\u5df2\u77e5\u7684\u6570\u503c<\/td><\/tr><tr><td>g<\/td><td>\u4efb\u4f55\u5bc4\u5b58\u5668\uff0c\u4f46\u5bc4\u5b58\u5668\u4e0d\u662f\u5e38\u89c4\u7684\u5bc4\u5b58\u5668<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u7ed3\u8bba<\/h2>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd GCC \u5185\u8054\u6c47\u7f16\u57fa\u7840\uff0c\u5e76\u5c06\u5176\u4e0e Intel \u5185\u8054\u6c47\u7f16\u8bed\u6cd5\u8fdb\u884c\u5bf9\u6bd4\uff0c\u4e3a\u4ee5\u540e\u5728\u4e0d\u540c\u5e73\u53f0\u8fdb\u884c\u8fc1\u79fb\u63d0\u4f9b\u5e2e\u52a9\u3002GCC \u5185\u8054\u6c47\u7f16\u8fd8\u6709\u5f88\u591a\u7684\u5185\u5bb9\u5728\u672c\u6587\u8fd8\u6ca1\u6709\u6d89\u53ca\u5230\uff0c\u66f4\u591a\u5185\u5bb9\u53ef\u67e5\u9605 GNU \u6587\u6863\u3002<\/p>\n\n\n\n<p>GCC \u5185\u8054\u6c47\u7f16\u4e0e Intel \u5185\u8054\u6c47\u7f16\u6709\u5f88\u591a\u76f8\u540c\u4e4b\u5904\uff0c\u4f46\u53c8\u6709\u5404\u81ea\u4e0d\u540c\u7684\u7279\u6027\u3002\u7279\u522b\u8981\u6ce8\u610f\u572864\u4f4d\u7f16\u8bd1\u73af\u5883\u4e0b\uff0cVC \u7f16\u8bd1\u5668\u4e0d\u518d\u652f\u6301\u5728 C \u8bed\u8a00\u4ee3\u7801\u91cc\u63d2\u5165\u5185\u8054\u6c47\u7f16\uff0c\u800c\u662f\u4f7f\u7528\u4e86 intrinsics \u7684\u51fd\u6570\u5f0f\u6307\u4ee4\u6765\u4ee3\u66ff64\u4f4d\u6c47\u7f16\u6307\u4ee4\uff0c\u8be6\u60c5\u53ef\u67e5\u9605 Intel \u624b\u518c\u5b66\u4e60\u76f8\u5173\u51fd\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u524d\u6bb5\u65f6\u95f4\u548c\u5728\u540c\u5b66\u9662\u91cc\u7814\u7a76\u5d4c\u5165\u5f0f\u65b9\u5411\u7684\u4e00\u4f4d\u540c\u5b66\u4ecb\u7ecd\u4e86\u4e00\u4e0b x86 \u6c47\u7f16\uff0c\u53e6\u5916\u8fd8\u544a\u8bc9\u4ed6\u80fd\u5728 C \u8bed [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/posts\/1378"}],"collection":[{"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/comments?post=1378"}],"version-history":[{"count":0,"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/posts\/1378\/revisions"}],"wp:attachment":[{"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/media?parent=1378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/categories?post=1378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xbtzone.com\/blog\/wp-json\/wp\/v2\/tags?post=1378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}