This got me thinking: what are some examples of high-quality and/or beautiful x86 assembly? In fact, what about for other processor families as well?
Ask HN: What are some examples of beautiful x86 assembly code?
1–10 of 93 posts
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#2There was some discussion of it here a while ago: https://news.ycombinator.com/item?id=942684 (though unfortunately the site is now dead)
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#3Re: Ask HN: What are some examples of beautiful x86 assembly code?
#4Re: Ask HN: What are some examples of beautiful x86 assembly code?
#5...
and yes, I consider it beautiful x86 code :)
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#6Re: Ask HN: What are some examples of beautiful x86 assembly code?
#7https://github.com/kaneton/appendix-bios
OT: This brings back memories of tinkering with the MS-DOS boot process. Back then, the BIOS would read the MBR and copy its contents to 0x7C00 and start execution from there. So you could assemble your own code (using no less than MS-DOS debug) and plonk it into the MBR. I remember doing things like fooling the boot loader into thinking there's less ram than there actually was (639kB instead of 640kB) and using the unaccounted 1kB for placing your own code that could be triggered by a captured interrupt... Fun times!
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#8strlen():
LEN: MOV #-1, R0
1⊙ INC R0
TSTB (R1)+
BNE 1⊙
or take strcpy(): COPY: MOVB (R1)+, (R0)+
BNE COPY
versus the C version: void strcpy(char *s, char *t)
{
while (*s++ = *t++)
;
}
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.Re: Ask HN: What are some examples of beautiful x86 assembly code?
#9My 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. strlen(): LEN: MOV #-1, R0 1⊙ INC R0 TSTB (R1)+ BNE 1⊙ or take strcpy(): COPY: MOVB (R1)+, (R0)+ BNE COPY vers…