Live data from Hacker News

Ask HN: What are some examples of beautiful x86 assembly code?

news.ycombinator.com

51–60 of 93 posts

Re: Ask HN: What are some examples of beautiful x86 assembly code?

#51
post #12

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

I was confused until I noticed the "x" in front of "add".

Re: Ask HN: What are some examples of beautiful x86 assembly code?

#52
post #41

Duff'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…

> Note the '.section .rodata' directive which places ..., seemingly interleaved with code, in a read-only data section.

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?

#54
post #20

Well, 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.

Interesting. Have you tried generalizing that for higher dimensions?

Re: Ask HN: What are some examples of beautiful x86 assembly code?

#55
post #19
post #7

IBM 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'?

So yes, this was a TSR, except that it resided in unaccounted for memory. Also, since you put it into the MBR, it would get loaded into ram automatically with every boot, and no fiddling with autoexec.bat or anything where it could be easily discovered. All this of course, in trying to understand the fascinating world of viruses.

Re: Ask HN: What are some examples of beautiful x86 assembly code?

#57
post #12

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

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

Re: Ask HN: What are some examples of beautiful x86 assembly code?

#59
post #57

Earlier 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

I think it’s created by the man himself - having been through it it’s a very thorough coverage of the basic instruction set without delving too much into the windows specifics (it uses FASM syntax from what I recall)
Post reply on HN