Ask HN: What are some examples of beautiful x86 assembly code?
My interest, save for occasional tweak in ARM boot code, is mostly historical. Grew up on Z-80 assembly but really enjoy PDP-11 code for didactic purposes. You can easily see that the rise of optimising C compilers was helped by divergence from PDP instruction set. Not ever since C idioms map down so nicely.<p>strlen():<p><pre><code>  LEN:   MOV #-1, R0
  1⊙     INC R0
         TSTB (R1)+
         BNE 1⊙
</code></pre>
or take strcpy():<p><pre><code>  COPY:  MOVB (R1)+, (R0)+
         BNE COPY
</code></pre>
versus the C version:<p><pre><code>  void strcpy(char *s, char *t) 
  {
    while (*s++ = *t++)
      ;
  }
</code></pre>
It translates to the optimal machine code verbatim. It does not require any smarts of the compiler, at the expense of understanding on the side of the programmer. This is made possible by orthogonality of the instruction set, which in less well thought out designs was hacked around with special instructions (like LDIR on Z80). The price for that is you have to make compiler optimize these situations.