{"id":74,"date":"2012-02-26T17:00:40","date_gmt":"2012-02-26T16:00:40","guid":{"rendered":"http:\/\/kronotai.com\/wordpress\/?p=74"},"modified":"2012-02-26T17:00:40","modified_gmt":"2012-02-26T16:00:40","slug":"about-handling-of-cpu-flags","status":"publish","type":"post","link":"https:\/\/kronotai.com\/wordpress\/2012\/02\/26\/about-handling-of-cpu-flags\/","title":{"rendered":"About the handling of CPU flags"},"content":{"rendered":"<p>\t\t\t\t<![CDATA[In addition to the <a href=\"http:\/\/kronotai.com\/wordpress\/?p=60\" title=\"Stack tracking\">stack<\/a> the flags are also a core area of a decompiler. The decompiler has to know which flags are affected by each assembler command, the correct flag value and which flag combinations are tested by the conditional jump or set commands.\nNote in the following example the <code>cmp<\/code> command affects all relevant flags while the dec command affects some flags but not the carry flag which is tested by the jump command <code>jb<\/code>. This means that the <code>dec<\/code> command has no effect on the control flow and since also its changed register value is not used, it has no effect on the result value.\n\n\n<pre lang=\"asm\">\ntest:\n        movl    $10, %eax\n        cmpl    $10, %ebx\n        dec     %ecx\n        jb      .L1\n        movl    $7, %eax\n        jmp     .L2\n.L1:\n        movl    $42, %eax\n.L2:\n        ret\n<\/pre>\n\n\nA correct decompiled version could be:\n\n\n<pre lang=\"c\">\n\/\/ addr = 080483a0.0\n\/\/ signature= func(test, ret=[<0, int(undef, 4),,unknown>], para=[<0, int(undef, 4),p1,reg[ebx]>, <1, int(undef, 4),p2,reg[ecx]>], varargs=false)\n??? test(???)\n{\n  return p1  <  10 ? 42 : 7;\n}\n<\/pre>\n\n\nWrong would be a variant using <code>ecx<\/code>.\n]]>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\t\t\t\t<![CDATA[]]>\t\t <a href=\"https:\/\/kronotai.com\/wordpress\/2012\/02\/26\/about-handling-of-cpu-flags\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[18],"class_list":["post-74","post","type-post","status-publish","format-standard","hentry","category-decompiler","category-holdec","tag-flags"],"_links":{"self":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts\/74","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/comments?post=74"}],"version-history":[{"count":0,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/posts\/74\/revisions"}],"wp:attachment":[{"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/media?parent=74"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/categories?post=74"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kronotai.com\/wordpress\/wp-json\/wp\/v2\/tags?post=74"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}