I bought a nice little booklet of small x86 gems a few years back[1][2] and this one is my favorite: .loop: xadd rax,rdx loop .loop Fibonacci with two instructions. [1] https://www.amazon.com/dp/1502958082 [2] https://www.xorpd.net/pages/xchg_rax/snip_00.html
Ask HN: What are some examples of beautiful x86 assembly code?
51–60 of 93 posts
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#52Duff's device, as emitted by GCC[0], is a bit on the verbose side but still quite neat. In particular the single-instruction computed goto that uses a look-up table made up of 8 quad-words, filled in by the linker. Note the '.section .rodata' directive which actually places the quads pointers, seemingly interleaved with code, in a read-only data section. Note also the dec/test/jle instructions implementing the while…
It only specifies which section that part of "code" goes into, the linker pools it all up in a binary image and fills in the address for the tags when linking as directed by the linker script[0].
[0]: https://sourceware.org/binutils/docs/ld/Simple-Example.html
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#53The coolest one liner is xor eax,eax :) 1 cycle for setting register to 0.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#54Well, not written in assembly but uses x86 intrinsics: https://github.com/leni536/fast_hilbert_curve I'm pretty proud of it. It calculates the coordinates of the nth point on the hilbert curve. No loops, no branches. It uses the pext, pdep and popcount intrinsics creatively.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#55IBM PC x86 BIOS code: https://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…
What was the advantage of this over 'Terminate and Stay Resident'?
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#56Re: Ask HN: What are some examples of beautiful x86 assembly code?
#57I bought a nice little booklet of small x86 gems a few years back[1][2] and this one is my favorite: .loop: xadd rax,rdx loop .loop Fibonacci with two instructions. [1] https://www.amazon.com/dp/1502958082 [2] https://www.xorpd.net/pages/xchg_rax/snip_00.html
I’d like to add to this comment to say that the author has a fantastic assembly course available on udemy - very thorough and practical (teaching the basics in a win32 environment) https://www.udemy.com/x86-asm-foundations/
EDIT: Looks like it is. https://www.xorpd.net/pages/x86_adventures.html
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#58Come on, the movfuscator has to be the best x86 I've seen: https://github.com/xoreaxeaxeax/movfuscator
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#59Earlier quoted context omitted.
I’d like to add to this comment to say that the author has a fantastic assembly course available on udemy - very thorough and practical (teaching the basics in a win32 environment) https://www.udemy.com/x86-asm-foundations/
Is that series endorsed by xorpd or an account just called xorpd? Udemy is known for allowing anyone to steal, upload, and profit from video series. EDIT: Looks like it is. https://www.xorpd.net/pages/x86_adventures.html