{"id":1318,"date":"2018-10-25T23:13:52","date_gmt":"2018-10-25T15:13:52","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=1318"},"modified":"2018-10-26T14:35:56","modified_gmt":"2018-10-26T06:35:56","slug":"%e8%87%aa%e5%8a%a0%e8%bf%90%e7%ae%97a%e5%9c%a8%e6%b1%87%e7%bc%96%e4%b8%ad%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.yusian.com\/blog\/assembler\/2018\/10\/25\/2313521318.html","title":{"rendered":"\u81ea\u52a0\u8fd0\u7b97(a++)\u5728\u6c47\u7f16\u4e2d\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>1\u3001C++\u6e90\u4ee3\u7801<\/p>\n<pre lang=\"cpp\" line=\"1\">#include <iostream>\r\n#include <cmath>\r\n\r\nusing namespace std;\r\n\r\nint main(){\r\n    int a = 1;\r\n    int b = a++ + a++ + a++;\r\n    return 0;\r\n}<\/pre>\n<p>2\u3001xCode\u4e2d\u6c47\u7f16\u7ed3\u679c<\/p>\n<pre lang=\"asm\" line=\"1\">cplus`main:\r\n 0x100000f70 <+0>:  pushq  %rbp\r\n 0x100000f71 <+1>:  movq   %rsp, %rbp\r\n 0x100000f74 <+4>:  xorl   %eax, %eax\r\n 0x100000f76 <+6>:  movl   $0x0, -0x4(%rbp)\r\n 0x100000f7d <+13>: movl   $0x1, -0x8(%rbp);\u8bbe\u7f6e\u5c40\u90e8\u53d8\u91cf(a=1)\r\n \r\n ;\u7b2c\u4e00\u6b65(\u5de6\u8fd0\u7b97\u503c)%ecx\r\n 0x100000f84 <+20>: movl   -0x8(%rbp), %ecx;\u53d6\u51fa\u53d8\u91cf\u503c(1)[\u51c6\u5907\u7b2c\u4e00\u4e2a+\u53f7\u5de6\u8fd0\u7b97]\r\n\r\n 0x100000f87 <+23>: movl   %ecx, %edx;\u51c6\u5907\u7b2c\u4e00\u6b21a++\r\n 0x100000f89 <+25>: addl   $0x1, %edx;a++\r\n 0x100000f8c <+28>: movl   %edx, -0x8(%rbp);\u7b2c\u4e00\u6b21a++\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d(2)\r\n \r\n ;\u7b2c\u4e8c\u6b65(\u53f3\u8fd0\u7b97\u503c)%edx\r\n 0x100000f8f <+31>: movl   -0x8(%rbp), %edx;\u53d6\u51fa\u7b2c\u4e00\u6b21++\u7684\u7ed3\u679c(2)[\u7b2c\u4e00\u4e2a+\u53f7\u53f3\u8fd0\u7b97]\r\n \r\n 0x100000f92 <+34>: movl   %edx, %esi;\u51c6\u5907\u7b2c\u4e8c\u6b21a++\r\n 0x100000f94 <+36>: addl   $0x1, %esi;a++\r\n 0x100000f97 <+39>: movl   %esi, -0x8(%rbp);\u7b2c\u4e8c\u6b21a++\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d(3)\r\n \r\n ;\u7b2c\u4e09\u6b65(\u7b2c\u4e00\u4e2a+\u8fd0\u7b97)(\u8fd4\u56de\u503c)%ecx\r\n 0x100000f9a <+42>: addl   %edx, %ecx;\u8fd0\u7b97\u7b2c\u4e00\u4e2a+\u53f7(1+2=3)[\u8fd0\u7b97\u8fd4\u56de\u503c\uff0c\u7b2c\u4e8c\u4e2a+\u53f7\u7684\u5de6\u8fd0\u7b97\u503c]\r\n \r\n ;\u7b2c\u56db\u6b65(\u53f3\u8fd0\u7b97\u503c)%edx\r\n 0x100000f9c <+44>: movl   -0x8(%rbp), %edx;\u53d6\u51fa\u7b2c\u4e8c\u6b21a++\u540e\u7684\u7ed3\u679c(3)[\u7b2c\u4e8c\u4e2a+\u53f7\u7684\u53f3\u8fd0\u7b97\u503c]\r\n \r\n 0x100000f9f <+47>: movl   %edx, %esi;\u51c6\u5907\u7b2c\u4e09\u6b21a++\r\n 0x100000fa1 <+49>: addl   $0x1, %esi;a++\r\n 0x100000fa4 <+52>: movl   %esi, -0x8(%rbp);\u7b2c\u4e09\u6b21a++\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d(4)\r\n \r\n ;\u7b2c\u4e94\u6b65(\u7b2c\u4e8c\u4e2a+\u8fd0\u7b97)(\u8fd4\u56de\u503c)%ecx\r\n 0x100000fa7 <+55>: addl   %edx, %ecx;\u8fd0\u7b97\u7b2c\u4e8c\u4e2a+\u53f7(3+3=6)[\u8fd0\u7b97\u8fd4\u56de\u503c]\r\n \r\n ;\u7b2c\u516d\u6b65(\u8fd0\u7b97\u7ed3\u675f\uff0c\u8d4b\u503c)\r\n 0x100000fa9 <+57>: movl   %ecx, -0xc(%rbp);\u7ed3\u679c\u4f20\u7ed9\u5c40\u90e8\u53d8\u91cf(c=6)\r\n \r\n \r\n 0x100000fac <+60>: popq   %rbp\r\n 0x100000fad <+61>: retq<\/pre>\n<p>3\u3001\u5982\u679c\u5bf9\u4e0a\u8ff0\u7406\u89e3\u6709\u4e00\u70b9\u96be\u5ea6\uff0c\u53ef\u4ee5\u7b80\u5316\u4e00\u4e0b\u8fc7\u7a0b\uff0c\u56e0\u4e3a\u90fd\u662fa\uff0c\u6240\u4ee5\u5bb9\u6613\u7ed5\u6655\uff0c<strong>\u91cd\u70b9\u5728\u4e8e\u7406\u89e3\u8fd0\u7b97\u65f6\uff0c\u5de6\u8fd0\u7b97\u6570\u3001\u53f3\u8fd0\u7b97\u6570\u51c6\u5907\u5230\u5bc4\u5b58\u5668\u4e2d\uff0c\u8ba1\u7b97\u7ed3\u679c\u8fd4\u56de\u5230\u76f8\u5173\u53d8\u91cf\u4e2d\u8fd9\u4e00\u539f\u5219\uff01\uff01\uff01<\/strong><!--more--><\/p>\n<pre lang=\"cpp\" line=\"1\">#include <iostream>\r\n#include <cmath>\r\n\r\nusing namespace std;\r\n\r\nint main(){\r\n    int a = 1,b = 1,c = 1;\r\n    int d = a++ + b++ + c++;\r\n    return 0;\r\n}<\/pre>\n<pre lang=\"asm\" line=\"1\">cplus`main:\t\r\n    0x100000f60 <+0>:  pushq  %rbp\r\n    0x100000f61 <+1>:  movq   %rsp, %rbp\r\n    0x100000f64 <+4>:  xorl   %eax, %eax\r\n    0x100000f66 <+6>:  movl   $0x0, -0x4(%rbp)\r\n    0x100000f6d <+13>: movl   $0x1, -0x8(%rbp)\r\n    0x100000f74 <+20>: movl   $0x1, -0xc(%rbp)\r\n    0x100000f7b <+27>: movl   $0x1, -0x10(%rbp)\r\n\t\r\n    0x100000f82 <+34>: movl   -0x8(%rbp), %ecx;\u53d6\u51faa\u3010\u7b2c1\u4e2a+\u8fd0\u7b97\u7684\u5de6\u8fd0\u7b97\u6570\u3011\r\n    0x100000f85 <+37>: movl   %ecx, %edx\r\n    0x100000f87 <+39>: addl   $0x1, %edx;a++\r\n    0x100000f8a <+42>: movl   %edx, -0x8(%rbp);\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d\r\n\t\r\n    0x100000f8d <+45>: movl   -0xc(%rbp), %edx;\u53d6\u51fab\u3010\u7b2c1\u4e2a+\u8fd0\u7b97\u7684\u53f3\u8fd0\u7b97\u6570\u3011\r\n    0x100000f90 <+48>: movl   %edx, %esi\r\n    0x100000f92 <+50>: addl   $0x1, %esi;b++\r\n    0x100000f95 <+53>: movl   %esi, -0xc(%rbp);\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d\r\n\t\r\n    0x100000f98 <+56>: addl   %edx, %ecx;\u6267\u884c\u7b2c1\u4e2a+\u8fd0\u7b97(1+1=2)\u3010\u7b2c2\u4e2a+\u8fd0\u7b97\u7684\u5de6\u8fd0\u7b97\u6570\u3011\r\n\t\r\n    0x100000f9a <+58>: movl   -0x10(%rbp), %edx;\u53d6\u51fac\u3010\u7b2c2\u4e2a+\u8fd0\u7b97\u7684\u53f3\u8fd0\u7b97\u6570\u3011\r\n    0x100000f9d <+61>: movl   %edx, %esi\r\n    0x100000f9f <+63>: addl   $0x1, %esi;c++\r\n    0x100000fa2 <+66>: movl   %esi, -0x10(%rbp);\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d\r\n\t\r\n    0x100000fa5 <+69>: addl   %edx, %ecx;\u6267\u884c\u7b2c2\u4e2a+\u8fd0\u7b97(2+1=3)\r\n\t\r\n    0x100000fa7 <+71>: movl   %ecx, -0x14(%rbp);\u7ed3\u679c\u8fd4\u56de\u53d8\u91cf\u4e2d\r\n    0x100000faa <+74>: popq   %rbp\r\n    0x100000fab <+75>: retq<\/pre>\n<p>4\u3001\u7d22\u6027\u518d\u6765\u4e00\u4e2a++a\u7684\u5427<br \/>\n4.1\u3001C++\u53caAT&#038;A\u6c47\u7f16<\/p>\n<pre lang=\"cpp\" line=\"1\">#include <iostream>\r\n#include <cmath>\r\n\r\nusing namespace std;\r\n\r\nint main(){\r\n    int a = 1,b = 1,c = 1;\r\n    int d = ++a + ++a + ++a;\r\n    return 0;\r\n}<\/pre>\n<pre lang=\"asm\" line=\"1\">cplus`main:\r\n    0x100000f70 <+0>:  pushq  %rbp\r\n    0x100000f71 <+1>:  movq   %rsp, %rbp\r\n    0x100000f74 <+4>:  xorl   %eax, %eax\r\n    0x100000f76 <+6>:  movl   $0x0, -0x4(%rbp)\r\n    0x100000f7d <+13>: movl   $0x1, -0x8(%rbp)\r\n    0x100000f84 <+20>: movl   $0x1, -0xc(%rbp)\r\n    0x100000f8b <+27>: movl   $0x1, -0x10(%rbp)\r\n    ;\u7b2c1\u4e2aa++\r\n    0x100000f92 <+34>: movl   -0x8(%rbp), %ecx\r\n    0x100000f95 <+37>: addl   $0x1, %ecx\r\n    0x100000f98 <+40>: movl   %ecx, -0x8(%rbp)\r\n    ;\u7b2c2\u4e2aa++\r\n    0x100000f9b <+43>: movl   -0x8(%rbp), %edx\r\n    0x100000f9e <+46>: addl   $0x1, %edx\r\n    0x100000fa1 <+49>: movl   %edx, -0x8(%rbp)\r\n    ;(a++)+(a++)\r\n    0x100000fa4 <+52>: addl   %edx, %ecx\r\n    ;\u7b2c3\u4e2aa++\r\n    0x100000fa6 <+54>: movl   -0x8(%rbp), %edx\r\n    0x100000fa9 <+57>: addl   $0x1, %edx\r\n    0x100000fac <+60>: movl   %edx, -0x8(%rbp)\r\n    ;((a++)+(a++))+(a++)\r\n    0x100000faf <+63>: addl   %edx, %ecx\r\n    ;\u8fd4\u56de\u503c\r\n    0x100000fb1 <+65>: movl   %ecx, -0x14(%rbp)\r\n    0x100000fb4 <+68>: popq   %rbp\r\n    0x100000fb5 <+69>: retq <\/pre>\n<p>4.2\u30018086\u6c47\u7f16<\/p>\n<pre lang=\"asm\" line=\"1\">assume ss:stack, ds:data, cs:code\r\n\r\nstack segment\r\n     db 20h dup(0cch)\r\nstack ends\r\n\r\ndata segment\r\n     db 20h dup(0cch)\r\ndata ends\r\n\r\ncode segment\r\nstart:\r\n     mov ax, stack\r\n     mov ss, ax\r\n     mov sp, 20h\r\n     mov ax, data\r\n     mov ds, ax\r\n     \r\n     push bp\r\n     mov bp, sp\r\n     sub sp, 10h  \r\n     ;------\u4e1a\u52a1\u4ee3\u7801----Begain\r\n     ;int a = 1;   \r\n     ;int b = ++a + ++a + ++a;\r\n     mov word ptr [bp-2], 1h\r\n     ;\u7b2c1\u4e2a++\u8fd0\u7b97\u3010\u7b2c1\u4e2a+\u5de6\u8fd0\u7b97\u6570\u3011\r\n     mov ax, [bp-2]\r\n     add ax, 1h\r\n     mov word ptr [bp-2], ax\r\n     ;\u7b2c2\u4e2a++\u8fd0\u7b97\u3010\u7b2c1\u4e2a+\u53f3\u8fd0\u7b97\u6570\u3011\r\n     mov bx, [bp-2]\r\n     add bx,1h\r\n     mov word ptr [bp-2], bx\r\n     \r\n     add ax, bx;\u7b2c1\u4e2a+\u8fd0\u7b97\u3010\u7b2c2\u4e2a+\u5de6\u8fd0\u7b97\u6570\u3011\r\n     ;\u7b2c3\u4e2a++\u8fd0\u7b97\u3010\u7b2c2\u4e2a+\u53f3\u8fd0\u7b97\u6570\u3011\r\n     mov bx, [bp-2]\r\n     add bx, 1h\r\n     mov word ptr [bp-2], bx\r\n     \r\n     add ax, bx;\u7b2c2\u4e2a+\u8fd0\u7b97\u3010\u8fd4\u56de\u503c\uff0c\u6216\u4e0b\u4e00\u4e2a\u5de6\u8fd0\u7b97\u6570\u3011\r\n     mov word ptr [bp-4], ax;\u8fd4\u56de\u503c\u8d4b\u7ed9b                            \r\n     ;------\u4e1a\u52a1\u4ee3\u7801----End\r\n     \r\n     ;Exit\r\n     mov ah, 4ch\r\n     int 21h\r\ncode ends\r\nend start<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2018\/10\/assembler-300x154.png\" alt=\"\" width=\"600\" height=\"308\" class=\"alignnone size-medium wp-image-1328\" srcset=\"https:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2018\/10\/assembler-300x154.png 300w, https:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2018\/10\/assembler-768x393.png 768w, https:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2018\/10\/assembler-1024x524.png 1024w, https:\/\/www.yusian.com\/blog\/wp-content\/uploads\/2018\/10\/assembler-624x319.png 624w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001C++\u6e90\u4ee3\u7801 #include #include using namespace std; int main(){ int a = 1; int b = a++ + a++ + a++; return 0; } 2\u3001xCode\u4e2d\u6c47\u7f16\u7ed3\u679c cplus`main: 0x100000f70 : pushq %rbp 0x100000f71 : movq %rsp, %rbp 0x100000f74 : xorl %eax, %eax 0x100000f76 : movl $0x0, -0x4(%rbp) 0x100000f7d : movl $0x1, -0x8(%rbp);\u8bbe\u7f6e\u5c40\u90e8\u53d8\u91cf(a=1) ;\u7b2c\u4e00\u6b65(\u5de6\u8fd0\u7b97\u503c)%ecx 0x100000f84 : movl -0x8(%rbp), %ecx;\u53d6\u51fa\u53d8\u91cf\u503c(1)[\u51c6\u5907\u7b2c\u4e00\u4e2a+\u53f7\u5de6\u8fd0\u7b97] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124],"tags":[135,129,89,127,121],"class_list":["post-1318","post","type-post","status-publish","format-standard","hentry","category-assembler","tag-a","tag-asm","tag-c","tag-127","tag-121"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/comments?post=1318"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1318\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}