{"id":451,"date":"2007-08-06T23:09:53","date_gmt":"2007-08-07T06:09:53","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/tonights-asm-strangeness\/"},"modified":"2007-08-07T06:23:15","modified_gmt":"2007-08-07T13:23:15","slug":"tonights-asm-strangeness","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/tonights-asm-strangeness\/","title":{"rendered":"Tonight&#8217;s ASM Strangeness"},"content":{"rendered":"<p>Check out this sequence:<\/p>\n<ul>\n<li>copy 32-bit register A to register B<\/li>\n<li>shift B <strike>left<\/strike> <em>right<\/em> by 0x1F (thanks to Reimar for spotting the mistake)<\/li>\n<li>subtract 1 from B<\/li>\n<li>logically AND B against A<\/li>\n<\/ul>\n<p>Eventually, it dawned on me that the sequence saturates an integer to a minimum value of 0, only without using any of the more traditional branching logic for such an operation.<\/p>\n<p>Speed demons, these programmers. They used some neat tricks. It looks like gcc didn&#8217;t, though. Either that or I don&#8217;t understand the deeper meaning of the instruction &#8220;lea esi, [esi+0]&#8221;. It strikes me as a NOP. But that&#8217;s not quite as bad as some code observed in another gcc-compiled module recently that saw fit to execute &#8220;mov eax, eax&#8221; after a function call before moving eax (the function&#8217;s return value) to its final destination.<\/p>\n<p>I&#8217;m not complaining since, when the time comes (hopefully soon) to reverse engineer that module, the naive compilation will make the task more straightforward.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check out this sequence: copy 32-bit register A to register B shift B left right by 0x1F (thanks to Reimar for spotting the mistake) subtract 1 from B logically AND B against A Eventually, it dawned on me that the sequence saturates an integer to a minimum value of 0, only without using any of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-reverse-engineering"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":0,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}