{"id":1218,"date":"2006-03-14T23:51:17","date_gmt":"2006-03-15T07:51:17","guid":{"rendered":"http:\/\/www.pagetable.com\/?p=4"},"modified":"2006-03-14T23:51:17","modified_gmt":"2006-03-15T07:51:17","slug":"first-assembly-puzzle","status":"publish","type":"post","link":"https:\/\/www.pagetable.com\/?p=1218","title":{"rendered":"First assembly puzzle!"},"content":{"rendered":"<p>This is our first assembly language puzzle for the new site! These puzzles are tests to see\u00c2\u00a0whether you are good enough of an assembly nerd, and to learn some tricks if you&#8217;re not =^_^=<\/p>\n<p>Our first puzzle is of a classic type: size optimization.\u00c2\u00a0 It is for x86-32 assembly language, certainly the most widely known assembly language.\u00c2\u00a0 We will definitely do other puzzles for other processors though!<\/p>\n<p>You might find that many of these puzzles are good ideas to place into compilers and other automated assembly\/machine code generators.<\/p>\n<p>The puzzle: In terms of opcode bytes, find the smallest sequence of x86-32 instructions to implement the following C\/C++ code:<\/p>\n<p>if ((x == 0) || (y == 0))<br \/>\n\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 goto label;<\/p>\n<p>Rules:<\/p>\n<ul>\n<li>x and y are 32-bit integers or pointers.<\/li>\n<li>x and y are each already in general-purpose registers or memory locations of your choice.<\/li>\n<li>Do not assume a particular state of the flags, except that you may assume the direction flag is always clear as that is its usual state.<\/li>\n<li>You may destroy any general-purpose registers or memory locations as you see fit, including the locations of x and y.<\/li>\n<li>Assume that label is within range of a short jump.<\/li>\n<li>Do not assume that you have access to protected instructions.<\/li>\n<li>In general, answers that are the same size but faster or less destructive are considered better than others.<\/li>\n<\/ul>\n<p>I was rather verbose in the rules because it&#8217;s the first puzzle.\u00c2\u00a0 Future puzzles won&#8217;t necessarily mention these restrictions.<\/p>\n<p>Answers that don&#8217;t fit all the rules but have other merits like creativity are certainly welcomed!<\/p>\n<p>The smallest answer I could find was 6 bytes.\u00c2\u00a0 The straightforward answer is 8 bytes.\u00c2\u00a0 Good luck!<\/p>\n<p>-Myria<\/p>\n<p>(check comments for solution(s))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is our first assembly language puzzle for the new site! These puzzles are tests to see\u00c2\u00a0whether you are good enough of an assembly nerd, and to learn some tricks if you&#8217;re not =^_^= Our first puzzle is of a classic type: size optimization.\u00c2\u00a0 It is for x86-32 assembly language, certainly the most widely known &#8230; <a title=\"First assembly puzzle!\" class=\"read-more\" href=\"https:\/\/www.pagetable.com\/?p=1218\" aria-label=\"Read more about First assembly puzzle!\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-1218","post","type-post","status-publish","format-standard","hentry","category-puzzle"],"_links":{"self":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1218"}],"version-history":[{"count":0,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=\/wp\/v2\/posts\/1218\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pagetable.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}