{"id":1330,"date":"2018-10-26T16:19:07","date_gmt":"2018-10-26T08:19:07","guid":{"rendered":"http:\/\/www.yusian.com\/blog\/?p=1330"},"modified":"2018-10-26T16:22:29","modified_gmt":"2018-10-26T08:22:29","slug":"c%e4%b8%adif-else-%e4%b8%8efor-%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\/26\/1619071330.html","title":{"rendered":"C++\u4e2dif&#8230;else&#8230;\u4e0efor(&#8230;)\u5728\u6c47\u7f16\u4e2d\u7684\u5b9e\u73b0"},"content":{"rendered":"<p>1\u3001\u7f16\u5199\u4e24\u4e2a\u7b80\u5355\u7684\u6761\u4ef6\u8bed\u53e5\u6765\u53cd\u6c47\u7f16\u4e00\u4e0b\u770b\u6700\u7ec8\u673a\u5668\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u4e0b\u793a\u4f8b\u662f\u5728XCode\u4e2d\u53cd\u6c47\u7f16\u7684\uff0c\u5373AT&#038;T\u6c47\u7f16\uff0c8086\u6216win32\u4e5f\u662f\u76f8\u540c\u7684\u539f\u7406<br \/>\n1.1\u3001if&#8230;else&#8230;<\/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 = 0;\r\n    int b = 0;\r\n    if (a > 0){\r\n        b = 1;\r\n    }else{\r\n        b = 2;\r\n    }\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>:  movl   $0x0, -0x4(%rbp)\r\n    0x100000f7b <+11>: movl   $0x0, -0x8(%rbp);int a\r\n    0x100000f82 <+18>: movl   $0x0, -0xc(%rbp);int b\r\n\t\r\n    ;if...else...\u5f00\u59cb\r\n    ;1\u3001\u5c0f\u4e8e\u6216\u7b49\u4e8e\u5219\u8df3\u8f6c\u52303\u30100x100000f9f\u3011\r\n    0x100000f89 <+25>: cmpl   $0x0, -0x8(%rbp)\r\n    0x100000f8d <+29>: jle    0x100000f9f\r\n\t\r\n    ;2.1\u3001\u7b26\u5408\u6761\u4ef6\u5219\u6267\u884cif\u6761\u4ef6\u4e0b\u7684\u4ee3\u7801\r\n    0x100000f93 <+35>: movl   $0x1, -0xc(%rbp);b=1\r\n    ;2.2\u3001\u6267\u884c\u7ed3\u675f\u540e\u76f4\u63a5\u8df3\u8f6c\u5230\u7ed3\u5c3e\r\n    0x100000f9a <+42>: jmp    0x100000fa6\r\n\t\r\n    ;3\u3001else\u6761\u4ef6\u4e0b\u7684\u4ee3\u7801\r\n    0x100000f9f <+47>: movl   $0x2, -0xc(%rbp);b=2\r\n    ;if...else...\u7ed3\u675f\r\n\t\r\n    0x100000fa6 <+54>: xorl   %eax, %eax\r\n    0x100000fa8 <+56>: popq   %rbp\r\n    0x100000fa9 <+57>: retq  <\/pre>\n<p>1.2\u3001for(&#8230;;&#8230;;&#8230;)<!--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 = 0;\r\n    for (int i = 0; i < 5; i++){\r\n        a = 1;\r\n    }\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>:  movl   $0x0, -0x4(%rbp)\r\n    0x100000f7b <+11>: movl   $0x0, -0x8(%rbp);int a = 0\r\n    0x100000f82 <+18>: movl   $0x0, -0xc(%rbp);int i = 0\r\n\r\n    ;----for----start\r\n    ;1\u3001for\u5faa\u73af\u5f00\u59cb\uff0c\u9996\u5148\u8fdb\u884c\u6761\u4ef6\u5224\u65ad\u3010\u4e0d\u7b26\u5408\u5219\u8df3\u8f6c\u5230\u7ed3\u5c3e\u5730\u57400x100000fa8\u3011\r\n    0x100000f89 <+25>: cmpl   $0x5, -0xc(%rbp);if(i < 5)\r\n    0x100000f8d <+29>: jge    0x100000fa8;\r\n    ;2\u3001for\u5faa\u73af\u4e2d\u7684\u4e1a\u52a1\u4ee3\u7801\r\n    0x100000f93 <+35>: movl   $0x1, -0x8(%rbp);(a=1)\r\n    ;3\u3001for\u5faa\u73af\u4e2d\u4fee\u6539\u6761\u4ef6\u503c\r\n    0x100000f9a <+42>: movl   -0xc(%rbp), %eax;\u53d6\u51fai\u7684\u503c\r\n    0x100000f9d <+45>: addl   $0x1, %eax;i++\r\n    0x100000fa0 <+48>: movl   %eax, -0xc(%rbp);\u56de\u5199\u5230\u53d8\u91cf\r\n    ;4\u3001for\u5faa\u73af\u518d\u6b21\u5224\u65ad\r\n    0x100000fa3 <+51>: jmp    0x100000f89\u3010\u8f6c\u5230\u5faa\u73af\u5f00\u59cb\u4f4d\u7f6e\u3011\r\n    ;----for----end\r\n\r\n    0x100000fa8 <+56>: xorl   %eax, %eax\r\n    0x100000faa <+58>: popq   %rbp\r\n    0x100000fab <+59>: retq   <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u7f16\u5199\u4e24\u4e2a\u7b80\u5355\u7684\u6761\u4ef6\u8bed\u53e5\u6765\u53cd\u6c47\u7f16\u4e00\u4e0b\u770b\u6700\u7ec8\u673a\u5668\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u4e0b\u793a\u4f8b\u662f\u5728XCode\u4e2d\u53cd\u6c47\u7f16\u7684\uff0c\u5373AT&#038;T\u6c47\u7f16\uff0c8086\u6216win32\u4e5f\u662f\u76f8\u540c\u7684\u539f\u7406 1.1\u3001if&#8230;else&#8230; #include #include using namespace std; int main(){ int a = 0; int b = 0; if (a > 0){ b = 1; }else{ b = 2; } return 0; } cplus`main: 0x100000f70 : pushq %rbp 0x100000f71 : movq %rsp, %rbp 0x100000f74 : movl $0x0, -0x4(%rbp) 0x100000f7b : movl $0x0, -0x8(%rbp);int a 0x100000f82 : [&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":[129,134,138,137,127,136,121],"class_list":["post-1330","post","type-post","status-publish","format-standard","hentry","category-assembler","tag-asm","tag-att","tag-for","tag-if","tag-127","tag-136","tag-121"],"_links":{"self":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1330","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=1330"}],"version-history":[{"count":0,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/posts\/1330\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/media?parent=1330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/categories?post=1330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yusian.com\/blog\/wp-json\/wp\/v2\/tags?post=1330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}