{"id":235,"date":"2006-03-29T19:17:56","date_gmt":"2006-03-30T03:17:56","guid":{"rendered":"http:\/\/multimedia.cx\/eggs\/?p=235"},"modified":"2006-03-29T19:23:19","modified_gmt":"2006-03-30T03:23:19","slug":"bizarre-asm-construct-of-the-day","status":"publish","type":"post","link":"https:\/\/multimedia.cx\/eggs\/bizarre-asm-construct-of-the-day\/","title":{"rendered":"Bizarre ASM Construct Of The Day"},"content":{"rendered":"<p>Check out this piece of x86 ASM arcana:<\/p>\n<pre>\r\n  lea   edx, [edx+1]\r\n<\/pre>\n<p>What on earth? This appears to be functionally equivalent to:<\/p>\n<pre>\r\n  inc   edx\r\n<\/pre>\n<p>So, what, was the compiler\/assembler or possibly the original coder just trying to show off with a single overachieving x86 instruction like lea? Actually, a closer analysis of the surrounding ASM instructions may reveal what is happening here:<\/p>\n<pre>\r\n  cmp   ebx, <em>value<\/em>\r\n  mov   al, [edx]\r\n  lea   edx, [edx+1]\r\n  mov   [edi], al\r\n  lea   edi, [edi+1]\r\n  jz    <em>address<\/em>\r\n<\/pre>\n<p>The conditional branch at the end of the block depends on the flags set by the comparison at the start. Per my understanding, neither mov nor lea modify flags but inc probably would (I can never find a good x86 reference&#8211; that includes flag data&#8211; when I need one). Why not perform the comparison just before the conditional branch? Mine is not to question why. But I imagine that someone will comment that this is an obscure optimization trick for original Pentium machines or some such.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What do you make of this?<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-235","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\/235","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=235"}],"version-history":[{"count":0,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"wp:attachment":[{"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multimedia.cx\/eggs\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}