{"id":1049,"date":"2022-03-01T17:42:59","date_gmt":"2022-03-01T09:42:59","guid":{"rendered":"https:\/\/www.xianwaizhiyin.net\/?p=1049"},"modified":"2022-07-28T08:49:51","modified_gmt":"2022-07-28T00:49:51","slug":"x86%e6%b1%87%e7%bc%96%e5%85%a5%e9%97%a8-%e5%af%84%e5%ad%98%e5%99%a832%e4%bd%8d-%e9%9b%b6%e6%95%a3","status":"publish","type":"post","link":"https:\/\/www.xianwaizhiyin.net\/?p=1049","title":{"rendered":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563"},"content":{"rendered":"\n<p>\u5982\u679c\u7a0b\u5e8f\u8fd0\u884c\u5728 32\u4f4d \u6a21\u5f0f\u4e0b\uff0c\u5e38\u7528\u7684\u5bc4\u5b58\u5668\uff08register\uff09\u6709\u4ee5\u4e0b8\u4e2a\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>EAX\uff0cEAX \u662f <strong>\u7d2f\u52a0\u5668<\/strong> \uff08accumulator\uff09, \u5b83\u662f\u5f88\u591a\u52a0\u6cd5\u4e58\u6cd5\u6307\u4ee4\u7684\u7f3a\u7701\u5bc4\u5b58\u5668\u3002<\/li><li>EBX\uff0cEBX \u662f <strong>\u57fa\u5730\u5740<\/strong>\uff08base\uff09\u5bc4\u5b58\u5668, \u5728\u5185\u5b58\u5bfb\u5740\u65f6\u5b58\u653e\u57fa\u5730\u5740\u3002<\/li><li>ECX\uff0cECX \u662f <strong>\u8ba1\u6570\u5668<\/strong>\uff08counter\uff09\uff0c \u662f\u91cd\u590d\uff08REP\uff09\u524d\u7f00\u6307\u4ee4\u548cLOOP\u6307\u4ee4\u7684\u5185\u5b9a\u8ba1\u6570\u5668\u3002<\/li><li>EDX\uff0cEDX \u603b\u662f\u88ab\u7528\u6765\u653e\u6574\u6570\u9664\u6cd5\u4ea7\u751f\u7684\u4f59\u6570\u3002<\/li><li>EBP\uff0cEBP\u662f <strong>\u57fa\u5740\u6307\u9488<\/strong>\uff08BASE POINTER\uff09\uff0c \u8f6f\u4ef6\u7834\u89e3\u9886\u57df \u7ecf\u5e38\u7528\u5230\u8fd9\u4e2a \u57fa\u5740<\/li><li>ESP \uff0cESP \u662f <strong>\u5806\u6808\u6307\u9488<\/strong>\uff08stack point\uff09<\/li><li>ESI\/EDI\uff0c\u5206\u522b\u53eb\u505a <strong>\u6e90\/\u76ee\u6807\u7d22\u5f15\u5bc4\u5b58\u5668<\/strong>\uff08source\/destination index\uff09\uff0c\u56e0\u4e3a\u5728\u5f88\u591a\u5b57\u7b26\u4e32\u64cd\u4f5c\u6307\u4ee4\u4e2d\uff0c<code class=\"prettyprint\" >DS:ESI<\/code> \u6307\u5411\u6e90\u4e32\uff0c\u800c <code>ES:EDI<\/code> \u6307\u5411\u76ee\u6807\u4e32\u3002\u8fd9\u53e5\u8bdd\u6211\u4e5f\u4e0d\u660e\u767d<\/li><\/ol>\n\n\n\n<p>\u4e00\u5171\u6709 8 \u4e2a <strong>\u901a\u7528<\/strong> \u5bc4\u5b58\u5668\uff0c\u4ec0\u4e48\u662f<strong>\u901a\u7528<\/strong>\uff1f \u5c31\u662f EAX \u5bc4\u5b58\u5668\u53ef\u4ee5\u5e72 EBX \u5bc4\u5b58\u5668\u7684\u6d3b\u3002\u4ed6\u4eec\u5176\u5b9e\u90fd\u662f\u540c\u4e00\u79cd\u5bc4\u5b58\u5668\uff0cCPU \u63d0\u4f9b\u7684\u5bc4\u5b58\u5668\uff0c\u53ea\u662f\u4ece\u4f7f\u7528\u4e60\u60ef\u4e0a EAX \u53eb EAX\u3002\u4e58\u6cd5\u6307\u4ee4 \u80fd\u4e0d\u80fd\u7528 EBX \u5bc4\u5b58\u5668\uff1f\u4e5f\u662f\u53ef\u4ee5\u7684\uff0c\u53ea\u662f\u4f7f\u7528\u4e60\u60ef\u4e0a\u6ca1\u8fd9\u4e48\u641e\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>google_ads_content<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u8bb2\u89e3 EAX \u5bc4\u5b58\u5668\u7684\u4f7f\u7528\u3002\u4e0a\u9762\u8bf4\u4e86 \u4e58\u6cd5\u6307\u4ee4 \u9ed8\u8ba4\u4f7f\u7528 EAX\uff0c\u54b1\u4eec\u73b0\u5728\u5c31\u7528\u4ee3\u7801\u5b9e\u9645\u6f14\u793a\u4e00\u6b21 \u4e58\u6cd5\u6307\u4ee4\u600e\u4e48\u9ed8\u8ba4\u4f7f\u7528 EAX\u3002<\/p>\n\n\n\n<p>\u6c47\u7f16\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >        .file   &quot;main.c&quot;\n        .text\n        .globl  main\n        .type   main, @function\nmain:\n.LFB0:\n        .cfi_startproc\n        endbr32\n        pushl   %ebp\n        .cfi_def_cfa_offset 8\n        .cfi_offset 5, -8\n        movl    %esp, %ebp\n        .cfi_def_cfa_register 5\n        subl    $16, %esp\n        call    __x86.get_pc_thunk.ax\n        addl    $_GLOBAL_OFFSET_TABLE_, %eax\n        movl    $1, -4(%ebp)\n        addl    $1, -4(%ebp)\n        movl    $0, %eax\n        leave\n        .cfi_restore 5\n        .cfi_def_cfa 4, 4\n        ret\n        .cfi_endproc\n.LFE0:\n        .size   main, .-main\n        .section        .text.__x86.get_pc_thunk.ax,&quot;axG&quot;,@progbits,__x86.get_pc_thunk.ax,comdat\n        .globl  __x86.get_pc_thunk.ax\n        .hidden __x86.get_pc_thunk.ax\n        .type   __x86.get_pc_thunk.ax, @function\n__x86.get_pc_thunk.ax:\n.LFB1:\n        .cfi_startproc\n        movl    (%esp), %eax\n        ret\n        .cfi_endproc\n.LFE1:\n        .ident  &quot;GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0&quot;\n        .section        .note.GNU-stack,&quot;&quot;,@progbits\n        .section        .note.gnu.property,&quot;a&quot;\n        .align 4\n        .long    1f - 0f\n        .long    4f - 1f\n        .long    5\n0:\n        .string  &quot;GNU&quot;\n1:\n        .align 4\n        .long    0xc0000002\n        .long    3f - 2f\n2:\n        .long    0x3\n3:\n        .align 4\n4:\n\u200b<\/code><\/pre>\n\n\n\n<p>\u5148\u7528 gdb \u7b80\u5355\u8c03\u8bd5\u4e00\u4e0b\u4e0a\u9762\u8fd9\u6bb5\u6c47\u7f16\u4ee3\u7801\uff0c\u4e0d\u719f\u6089 gdb \u7684\u53ef\u4ee5\u5148\u770b\u4ee5\u4e0b\u6559\u7a0b\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/sourceware.org\/gdb\/current\/onlinedocs\/gdb\/\">\u300aGDB\u5b98\u7f51\u624b\u518c\u300b<\/a><\/li><li><\/li><\/ol>\n\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\uff0c\u662f 32 \u4f4d\u7684\u6c47\u7f16\uff0c\u5728 64\u4f4d \u7684 ubuntu\u4e0b\u8981 \u52a0\u4e0a <code class=\"prettyprint\" >-m32<\/code> \u624d\u80fd\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >gcc -m32 -o main32 main-32.s<\/code><\/pre>\n\n\n\n<p>\u518d\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u5165 gdb \u8c03\u8bd5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" ># \u8fd0\u884c gdb\ngdb .\/main32\n# \u663e\u793a\u5bc4\u5b58\u5668\u7a97\u53e3\nlayout regs\n# \u81ea\u52a8\u53cd\u6c47\u7f16\u540e\u9762\u8981\u6267\u884c\u7684\u4ee3\u7801\nset disassemble-next-line on\n# \u8bbe\u7f6e main \u65ad\u70b9\nb main\n# \u67e5\u770b\u6c47\u7f16\u4ee3\u7801\ndisassemble\n# \u67e5\u770b\u5bc4\u5b58\u5668\u7684\u503c\ni registers<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"850\" height=\"653\" src=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png\" alt=\"\" class=\"wp-image-1051\"\/><\/figure>\n\n\n\n<p>GDB \u8c03\u8bd5 C\u8bed\u8a00 \u7528\u7684\u662f s\uff08step\uff09 \u8ddf n\uff08next\uff09\uff0c\u5355\u6b65\u8c03\u8bd5\u6c47\u7f16\u662f <code class=\"prettyprint\" >si<\/code> \u8ddf <code>ni<\/code> \u3002<\/p>\n\n\n\n<p>GDB \u8c03\u8bd5\u6280\u5de7\u8bb2\u5b8c\u4e86\u3002\u4e0b\u9762\u5f00\u59cb\u4e00\u884c\u4e00\u884c\u4ee3\u7801\u8bb2\u89e3\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u4e0d\u719f\u6089 AT&amp;T \u6c47\u7f16\u8bed\u6cd5\u7684\u53ef\u4ee5\u5148\u5feb\u901f\u770b\u4e00\u904d \u5b98\u65b9\u6587\u6863 <a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_toc.html\">\u300aUsing as-The GNU Assembler\u300b<\/a><\/p>\n\n\n\n<p>\u76f8\u5e94\u7684 X86 \u6307\u4ee4\u53ef\u4ee5\u770b \u300a\u82f1\u7279\u5c14\u00ae 64 \u4f4d\u548c IA-32 \u67b6\u6784\u5f00\u53d1\u4eba\u5458\u624b\u518c\u300b\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/www.intel.cn\/content\/www\/cn\/zh\/architecture-and-technology\/64-ia-32-architectures-software-developer-vol-1-manual.html\">\u300a\u82f1\u7279\u5c14\u00ae 64 \u4f4d\u548c IA-32 \u67b6\u6784\u5f00\u53d1\u4eba\u5458\u624b\u518c\uff1a\u5377 1\u300b<\/a><\/li><li><a href=\"https:\/\/www.intel.cn\/content\/www\/cn\/zh\/architecture-and-technology\/64-ia-32-architectures-software-developer-vol-2a-manual.html\">\u300a\u82f1\u7279\u5c14\u00ae 64 \u4f4d\u548c IA-32 \u67b6\u6784\u5f00\u53d1\u4eba\u5458\u624b\u518c\uff1a\u5377 2A\u300b<\/a><\/li><\/ol>\n\n\n\n<p>\u4e0b\u9762\u5f00\u59cb\u4e00\u884c\u4e00\u884c\u4ee3\u7801\u8bb2\u89e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >    .file   &quot;main.c&quot;\n    .text\n    .globl  main\n    .type   main, @function<\/code><\/pre>\n\n\n\n<p>1\uff0c<a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_88.html#SEC90\"><code class=\"prettyprint\" >.file<\/code><\/a> \u5728\u5b98\u7f51\u7684\u624b\u518c \u7684\u6ce8\u91ca\u662f tells <code>as<\/code> that we are about to start a new logical file. string is the new file name.<\/p>\n\n\n\n<p>\u6211\u4e2a\u4eba\u731c\u6d4b\uff0c\u8fd9\u5e94\u8be5\u662f\u544a\u8bc9 <code class=\"prettyprint\" >gdb<\/code> \u5f80\u54ea\u4e2a\u6587\u4ef6\u505adebug\uff0c\u8c03\u8bd5\u7528\u7684\u3002<\/p>\n\n\n\n<p>2\uff0c<a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_129.html#SEC131\"><code class=\"prettyprint\" >.text<\/code><\/a>\uff0cTells <code>as<\/code> to assemble the following statements onto the end of the text subsection numbered subsection, which is an absolute expression. If subsection is omitted, subsection number zero is used.\uff08\u5b98\u7f51\u6ce8\u91ca\uff0c\u6211\u4e5f\u4e0d\u61c2\uff09<\/p>\n\n\n\n<p>3\uff0c<a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_91.html#SEC93\"><code class=\"prettyprint\" >.globl<\/code><\/a>\uff0c\u5e94\u8be5\u662f\u544a\u8bc9 \u94fe\u63a5\u5668 <code>ld<\/code> \u4e00\u4e9b\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>4\uff0c<a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_131.html#SEC133\"><code class=\"prettyprint\" >.type<\/code><\/a>\uff0c\u6211\u4e5f\u4e0d\u4f1a\uff0c\u81ea\u5df1\u770b\u6587\u6863\u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u7684 \u6c47\u7f16\u4ee3\u7801\uff0c<code class=\"prettyprint\" >.file<\/code>\uff0c<code>.text<\/code>\uff0c<code>.globl<\/code> \u7b49\u8fd9\u4e9b\uff0c\u5176\u5b9e\u662f\u4f2a\u6307\u4ee4\uff08<a href=\"https:\/\/ftp.gnu.org\/old-gnu\/Manuals\/gas-2.9.1\/html_node\/as_65.html#SEC67\">Assembler Directives<\/a>\uff09\u3002<\/p>\n\n\n\n<p>\u4f2a\u6307\u4ee4 \u662f\u6c47\u7f16\u5668 \u641e\u51fa\u6765\u7684\u4e1c\u897f\uff0c\u4e0d\u662fCPU\u6307\u4ee4\u96c6\u63d0\u4f9b\u7684\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a \u4f2a\u6307\u4ee4 \u662f\u57fa\u4e8e CPU\u6307\u4ee4\u96c6 \u5c01\u88c5\u7684\u3002<\/p>\n\n\n\n<p>\u4e0d\u4f2a\u7684\u6307\u4ee4\u5c31\u662f CPU \u6307\u4ee4\u96c6\uff0c<code class=\"prettyprint\" >pushl %rbp<\/code> \u8fd9\u79cd\u5c31\u662f\u771f\u6b63\u7684\u6307\u4ee4\u3002<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\uff0c\u4f2a\u6307\u4ee4 \u8ddf \u771f\u6b63\u7684\u6307\u4ee4\uff0c\u4f60\u7528\u6c47\u7f16\u7684\u65f6\u5019\uff0c\u662f\u6ca1\u6709\u611f\u77e5\u7684\u3002\u53ea\u662f\u5185\u90e8\u5b9e\u73b0\u6709\u533a\u522b\uff0c\u6240\u4ee5\u628a\u8fd9\u4e24\u4e2a\u4e1c\u897f\u770b\u6210\u4e00\u4e2a\u4e1c\u897f\u5c31\u884c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >main:\n.LFB0:\n   .cfi_startproc\n   endbr32\n   pushl  %ebp\n   .cfi_def_cfa_offset 8\n   .cfi_offset 5, -8<\/code><\/pre>\n\n\n\n<p>1\uff0c<code class=\"prettyprint\" >main:<\/code> \u8fd9\u884c\u4ee3\u7801\uff0c\u662f\u4e00\u4e2a label \uff0c\u628a\u5b83\u7406\u89e3\u6210 C\u8bed\u8a00\u7684 <code>goto<\/code> \u7684\u6807\u8bb0\u5c31\u884c\u3002<\/p>\n\n\n\n<p>2\uff0c<code class=\"prettyprint\" >.LFB0:<\/code> \u4e5f\u662f\u4e00\u4e2a <code>goto<\/code> \u6807\u8bb0\u3002\u5728\u6c47\u7f16\u91cc\u9762 \u662f <code>jmp<\/code> \u6307\u4ee4<\/p>\n\n\n\n<p>3\uff0c<code class=\"prettyprint\" >.cfi_startproc<\/code>\uff0c\u8fd9\u662f <a href=\"https:\/\/sourceware.org\/binutils\/docs\/as\/CFI-directives.html\">cfi<\/a> \u6307\u4ee4\uff0c\u8c03\u8bd5\u7528\u7684\u3002<\/p>\n\n\n\n<p>4\uff0c<code class=\"prettyprint\" >endbr32<\/code>\uff0c endbr instructions at the start of generated functions to make IBT (indirect branch tracking) work\u3002\u8fd8\u662f\u751f\u6210\u8c03\u8bd5\u4fe1\u606f\u7528\u7684\u3002<\/p>\n\n\n\n<p>5\uff0c<code class=\"prettyprint\" >pushl %ebp<\/code>\uff0c\u628a <code>ebp<\/code> \u5bc4\u5b58\u5668\u7684\u503c \u538b\u8fdb\u53bb <code>esp<\/code> \u5bc4\u5b58\u5668\uff0c\u4e0d\u7528\u5199\u4e0a <code>esp<\/code>\uff0c<code>push<\/code> \u6307\u4ee4\u9ed8\u8ba4\u5c31\u662f\u5b58\u5230 <code>esp<\/code> \u7684\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e2a <code class=\"prettyprint\" >push<\/code> \u6307\u4ee4\u975e\u5e38\u91cd\u8981\uff0c\u8be6\u89e3\u8bb2\u4e00\u4e0b\u3002\u540e\u9762\u7684 <code>l<\/code> \u662f <code>long<\/code> \u7684\u7f29\u5199\uff0c\u4ee3\u8868 4 \u5b57\u8282\u3002\u56e0\u4e3a\u8fd9\u662f 32 \u4f4d\u7684\u6c47\u7f16\u4ee3\u7801\u3002 64\u4f4d\u662f <code>pushq<\/code>\u3002<\/p>\n\n\n\n<p>\u4e3a\u4ec0\u4e48 \u7b2c\u4e00\u53e5 \u6307\u4ee4\u662f <code class=\"prettyprint\" >pushl %ebp<\/code> \uff1f<\/p>\n\n\n\n<p>\u8fd9\u662f\u56e0\u4e3a \u628a main \u51fd\u6570\u7684\u5165\u53e3\u4f5c\u4e3a\u4e00\u4e2a\u57fa\u5740\u65b9\u4fbf\u540e\u7eed\u64cd\u4f5c\u3002\u4e00\u822c <code class=\"prettyprint\" >push<\/code> \u6307\u4ee4 \u5bf9\u5e94\u4e00\u4e2a <code>pop<\/code>\uff0c\u6216\u8005\u7c7b\u4f3c <code>pop<\/code> \u7684\u529f\u80fd\u6307\u4ee4\u3002\u5728\u672c\u6587\u91cc\u9762\u662f <code>leave<\/code> \u6307\u4ee4\uff0c<code>leave<\/code> \u6307\u4ee4\u4f1a\u628a\u4e4b\u524d\u538b\u5728 <code>esp<\/code> \u7684\u5806\u6808\u6570\u636e\u5168\u90e8\u5f39\u51fa\u6765\u3002<\/p>\n\n\n\n<p>\u8fd9\u91cc\u8981 \u5199\u4e00\u4e0b push \u8ddf pop \u7684\u6c47\u7f16\u4ee3\u7801\u3002<\/p>\n\n\n\n<p>6\uff0c<code class=\"prettyprint\" >.cfi_def_cfa_offset 8<\/code> \uff0ccfi \u6307\u4ee4\uff0c\u770b\u8fd9\u7bc7\u6587\u7ae0 <a href=\"https:\/\/stackoverflow.com\/questions\/7534420\/gas-explanation-of-cfi-def-cfa-offset\">\u300agas-explanation-of-cfi-def-cfa-offset\u300b<\/a><\/p>\n\n\n\n<p>cfa \u5176\u5b9e\u5c31\u662f\u6c38\u8fdc\u6307\u5411 <code class=\"prettyprint\" >esp<\/code> \u7684\u5934\u90e8\uff0c\u8c03\u8bd5\u6307\u4ee4\uff0c\u81ea\u5df1\u5199\u6c47\u7f16\u4e00\u822c\u7528\u4e0d\u5230\u3002<\/p>\n\n\n\n<p>7\uff0c<code class=\"prettyprint\" >.cfi_offset 5, -8<\/code>\uff0c<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >   movl   %esp, %ebp\n   .cfi_def_cfa_register 5\n   subl   $16, %esp\n   call   __x86.get_pc_thunk.ax\n   addl   $_GLOBAL_OFFSET_TABLE_, %eax\n   movl   $1, -4(%ebp)\n   addl   $1, -4(%ebp)\n   movl   $0, %eax\n   leave\n   .cfi_restore 5\n   .cfi_def_cfa 4, 4\n   ret\n   .cfi_endproc<\/code><\/pre>\n\n\n\n<p>1\uff0c<code class=\"prettyprint\" >movl %esp, %ebp<\/code> \u628a esp \u5bc4\u5b58\u5668\u7684\u503c \u62f7\u8d1d\u7ed9 ebp\uff0c\u6ce8\u610f\u770b gdb \u7684 \u5bc4\u5b58\u5668\u7a97\u53e3\uff0cebp \u53d8\u767d\u8272\u4e86\u3002\u8fd8\u6709\u4e00\u4e2a\u91cd\u70b9 <code>eip<\/code> \u5bc4\u5b58\u5668\u6c38\u8fdc\u662f\u4e0b\u4e00\u6761\u8981\u6267\u884c\u7684\u6307\u4ee4\u7684\u5730\u5740\u3002\u8fd9\u91cc\u8fd8\u6709\u4e00\u4e2a\u91cd\u70b9\uff0cAT&amp;T \u7684 \u6e90\u548c\u76ee\u6807\u7684\u987a\u5e8f\u548c Intel \u76f8\u53cd\uff0c\u5728 intel \u91cc\u9762\u662f <code>mov ebp,esp<\/code>\u3002<\/p>\n\n\n\n<p>2\uff0c<code class=\"prettyprint\" >subl $16, %esp<\/code>\uff0c\u628a <code>esp<\/code> \u5bc4\u5b58\u5668\u7684\u503c\u51cf 16\uff0cAT&amp;T \u7684\u8bed\u6cd5 \u524d\u9762\u8981\u52a0 <code>$<\/code>\u3002<\/p>\n\n\n\n<p>3\uff0c<code class=\"prettyprint\" >call __x86.get_pc_thunk.ax<\/code>\uff0c\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\uff0cGOT\u8868\u3002\u9605\u8bfb \u8fd9\u7bc7\u6587\u7ae0 <a href=\"https:\/\/la13x.github.io\/2021\/04\/06\/ax\/#x86-get-pc-thunk\">\u300a__x86.get_pc_thunk.ax\u51fd\u6570\u300b<\/a><\/p>\n\n\n\n<p>4\uff0c<code class=\"prettyprint\" >movl $1, -4(%ebp)<\/code>\uff0c<code>addl $1, -4(%ebp)<\/code>\uff0c\u7528 GOT \u8868\u6765\u64cd\u4f5c\u53d8\u91cf\uff0c\u4e0d\u592a\u5bb9\u6613\u770b\u61c2\u3002<\/p>\n\n\n\n<p>5\uff0c<code class=\"prettyprint\" >leave<\/code>\uff0c\u9000\u51fa<\/p>\n\n\n\n<p><code class=\"prettyprint\" >\/lib32\/libc.so<\/code> \u4e0a\u9762\u7684\u6c47\u7f16\u7a0b\u5e8f\u662f\u5728\u8fd9\u4e2a\u8fd0\u884c\u65f6\u5e93\u91cc\u9762\u8dd1\u7684\u3002<\/p>\n\n\n\n<p>TODO\uff1a<\/p>\n\n\n\n<p>\u73b0\u5728\u5e94\u7528\u5c42\u7684\u6c47\u7f16\u4f18\u5316\uff0c\u901a\u5e38\u90fd\u662f\u5728 64 \u4f4d\u4e0b\u9762\u505a\u7684\u3002 32 \u4f4d\u672c\u6765\u5c31\u6ca1\u670964\u4f4d \u5feb\uff0c\u7528\u6c47\u7f16\u4e5f\u53ea\u662f\u5904\u7406\u4e00\u4e9b <code class=\"prettyprint\" >gcc<\/code> \u7f16\u8bd1\u4f18\u5316\u6ca1\u6709\u987e\u53ca\u5230\u7684\u5730\u65b9\uff0c\u60f3\u8ba9\u7a0b\u5e8f\u66f4\u5feb\u3002<\/p>\n\n\n\n<p>\u800c\u4e14\u73b0\u5728\u5927\u90e8\u5206\u673a\u5668\u90fd\u662f 64 \u4f4d\uff0c\u505a\u6c47\u7f16\u4f18\u5316\u662f\u9700\u8981\u7814\u53d1\u6210\u672c\u7684\uff0c\u901a\u5e38\u4e0d\u4f1a \u4e3a\u4e86\u4e00\u4e2a 32 \u4f4d\u7684\u7a0b\u5e8f\u53bb\u4f7f\u7528\u6c47\u7f16\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u672c\u4e66\uff0c\u53ea\u662f\u63d0\u53ca\u4e00\u4e0b 32 \u4f4d\u7684\u6c47\u7f16\u4e00\u70b9\u70b9\u77e5\u8bc6\uff0c\u540e\u7eed\u7684\u6c47\u7f16\u4ee3\u7801\u90fd\u662f\u57fa\u4e8e 64\u4f4d\u7684\u3002<\/p>\n\n\n\n<p>\u76f8\u5173\u9605\u8bfb\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/www.cnblogs.com\/qq78292959\/archive\/2012\/07\/20\/2600865.html\">EAX\u3001ECX\u3001EDX\u3001EBX\u5bc4\u5b58\u5668\u7684\u4f5c\u7528<\/a><\/li><li><a href=\"https:\/\/www.codetd.com\/article\/10611686\">\u300aUsing as-The GNU Assembler\u300b<\/a><\/li><li><a href=\"https:\/\/www.intel.cn\/content\/www\/cn\/zh\/architecture-and-technology\/64-ia-32-architectures-software-developer-vol-1-manual.html\">\u300a\u82f1\u7279\u5c14\u00ae 64 \u4f4d\u548c IA-32 \u67b6\u6784\u5f00\u53d1\u4eba\u5458\u624b\u518c\uff1a\u5377 1\u300b<\/a><\/li><li><a href=\"https:\/\/www.intel.cn\/content\/www\/cn\/zh\/architecture-and-technology\/64-ia-32-architectures-software-developer-vol-2a-manual.html\">\u300a\u82f1\u7279\u5c14\u00ae 64 \u4f4d\u548c IA-32 \u67b6\u6784\u5f00\u53d1\u4eba\u5458\u624b\u518c\uff1a\u5377 2A\u300b<\/a><\/li><\/ol>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u7531\u4e8e\u7b14\u8005\u7684\u6c34\u5e73\u6709\u9650\uff0c \u52a0\u4e4b\u7f16\u5199\u7684\u540c\u65f6\u8fd8\u8981\u53c2\u4e0e\u5f00\u53d1\u5de5\u4f5c\uff0c\u6587\u4e2d\u96be\u514d\u4f1a\u51fa\u73b0\u4e00\u4e9b\u9519\u8bef\u6216\u8005\u4e0d\u51c6\u786e\u7684\u5730\u65b9\uff0c\u6073\u8bf7\u8bfb\u8005\u6279\u8bc4\u6307\u6b63\u3002\u5982\u679c\u8bfb\u8005\u6709\u4efb\u4f55\u5b9d\u8d35\u610f\u89c1\uff0c\u53ef\u4ee5\u52a0\u6211\u5fae\u4fe1 Loken1\u3002QQ\uff1a2338195090\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u7a0b\u5e8f\u8fd0\u884c\u5728 32\u4f4d \u6a21\u5f0f\u4e0b\uff0c\u5e38\u7528\u7684\u5bc4\u5b58\u5668\uff08register\uff09\u6709\u4ee5\u4e0b8\u4e2a\u3002 EAX\uff0cEAX \u662f \u7d2f\u52a0\u5668 \uff08a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1049","post","type-post","status-publish","format-standard","hentry","category-assembly"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v18.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3<\/title>\n<meta name=\"description\" content=\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.xianwaizhiyin.net\/?p=1049\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3\" \/>\n<meta property=\"og:description\" content=\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.xianwaizhiyin.net\/?p=1049\" \/>\n<meta property=\"og:site_name\" content=\"\u5f26\u5916\u4e4b\u97f3\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-01T09:42:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-28T00:49:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"loken\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#website\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/\",\"name\":\"\u5f26\u5916\u4e4b\u97f3\",\"description\":\"FFmpeg\u3001WebRTC\uff0cSRS \u97f3\u89c6\u9891\u3001\u6d41\u5a92\u4f53\u6280\u672f\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.xianwaizhiyin.net\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049#primaryimage\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png\",\"contentUrl\":\"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png\",\"width\":850,\"height\":653},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049#webpage\",\"url\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049\",\"name\":\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3\",\"isPartOf\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049#primaryimage\"},\"datePublished\":\"2022-03-01T09:42:59+00:00\",\"dateModified\":\"2022-07-28T00:49:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3\"},\"description\":\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563\",\"breadcrumb\":{\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.xianwaizhiyin.net\/?p=1049\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/?p=1049#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.xianwaizhiyin.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3\",\"name\":\"loken\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/www.xianwaizhiyin.net\/#personlogo\",\"inLanguage\":\"zh-Hans\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g\",\"caption\":\"loken\"},\"sameAs\":[\"https:\/\/www.xianwaizhiyin.net\/\"],\"url\":\"https:\/\/www.xianwaizhiyin.net\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3","description":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.xianwaizhiyin.net\/?p=1049","og_locale":"zh_CN","og_type":"article","og_title":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3","og_description":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563","og_url":"https:\/\/www.xianwaizhiyin.net\/?p=1049","og_site_name":"\u5f26\u5916\u4e4b\u97f3","article_published_time":"2022-03-01T09:42:59+00:00","article_modified_time":"2022-07-28T00:49:51+00:00","og_image":[{"url":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png"}],"twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"loken","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/www.xianwaizhiyin.net\/#website","url":"https:\/\/www.xianwaizhiyin.net\/","name":"\u5f26\u5916\u4e4b\u97f3","description":"FFmpeg\u3001WebRTC\uff0cSRS \u97f3\u89c6\u9891\u3001\u6d41\u5a92\u4f53\u6280\u672f","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.xianwaizhiyin.net\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"ImageObject","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1049#primaryimage","inLanguage":"zh-Hans","url":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png","contentUrl":"https:\/\/www.xianwaizhiyin.net\/wp-content\/uploads\/2022\/03\/x86-3-0-1.png","width":850,"height":653},{"@type":"WebPage","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1049#webpage","url":"https:\/\/www.xianwaizhiyin.net\/?p=1049","name":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563 - \u5f26\u5916\u4e4b\u97f3","isPartOf":{"@id":"https:\/\/www.xianwaizhiyin.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.xianwaizhiyin.net\/?p=1049#primaryimage"},"datePublished":"2022-03-01T09:42:59+00:00","dateModified":"2022-07-28T00:49:51+00:00","author":{"@id":"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3"},"description":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563","breadcrumb":{"@id":"https:\/\/www.xianwaizhiyin.net\/?p=1049#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.xianwaizhiyin.net\/?p=1049"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.xianwaizhiyin.net\/?p=1049#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.xianwaizhiyin.net\/"},{"@type":"ListItem","position":2,"name":"X86\u6c47\u7f16\u5165\u95e8-\u5bc4\u5b58\u566832\u4f4d-\u96f6\u6563"}]},{"@type":"Person","@id":"https:\/\/www.xianwaizhiyin.net\/#\/schema\/person\/6605a70af752697df6b62f77c53298a3","name":"loken","image":{"@type":"ImageObject","@id":"https:\/\/www.xianwaizhiyin.net\/#personlogo","inLanguage":"zh-Hans","url":"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6320b5256dc36ef4243e0acf26144b8ac2668b478302ad154e95ce3202bc421?s=96&d=mm&r=g","caption":"loken"},"sameAs":["https:\/\/www.xianwaizhiyin.net\/"],"url":"https:\/\/www.xianwaizhiyin.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1049"}],"version-history":[{"count":3,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1049\/revisions"}],"predecessor-version":[{"id":2759,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=\/wp\/v2\/posts\/1049\/revisions\/2759"}],"wp:attachment":[{"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xianwaizhiyin.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}