Ask HN: What are some examples of beautiful x86 assembly code?
71–80 of 93 posts
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#72Re: Ask HN: What are some examples of beautiful x86 assembly code?
#73I 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
Can someone more versed in x86 explain to me how this works? It's been a long time since I've done any assembly, and that was MIPS, but I don't see how there's any sort of exit condition or anything. I'm guessing there's more to xadd than `x + y = z`?
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#74Earlier quoted context omitted.
If all functions took (rax, rbx, rcx, ...) and you had loop statement that defrements rcx and jumps unless zero, then how would you write fib-function’s body?
You raise a good question. At one time you would have only one loop running through the system as per my understanding. I am a little lost here.
It’s sometimes difficult to think about the assembly code in situ when you start to think about the operating system doing a ton of context switching and paging etc. in the background, which can distract your thought process from what’s right in front of you (as well as the operating system’s software interrupts / system calls on top of the basic ISA, which is another abstraction!)
Older systems had the currently running program as the entire context of the system at that point in time - in a similar way to embedded programming, which is imho a much easier realm to learn assembly in once you’ve got a bit of basic electronics under your belt!
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#75Re: Ask HN: What are some examples of beautiful x86 assembly code?
#76Earlier quoted context omitted.
If all functions took (rax, rbx, rcx, ...) and you had loop statement that defrements rcx and jumps unless zero, then how would you write fib-function’s body?
You raise a good question. At one time you would have only one loop running through the system as per my understanding. I am a little lost here.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#77I 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
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#78Come on, the movfuscator has to be the best x86 I've seen: https://github.com/xoreaxeaxeax/movfuscator
I was going to ask why? But then I read the single faq at the end: because I thought it would be funny...
It also fully avoids all branches.