Here's a wiki dedicated to very small x86 programs: http://www.sizecoding.org/wiki/Main_Page Lots of fun stuff there, like a scrolling Matrix screen saver in 8 bytes (!!) that jumps into the middle of an instruction: http://www.sizecoding.org/wiki/M8trix_8b
Ask HN: What are some examples of beautiful x86 assembly code?
81–90 of 93 posts
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#82Earlier 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
The exercises are open source and can be found here: https://github.com/xorpd/asm_prog_ex I think that more experienced developers can take the instruction set and bash through the exercises.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#83Earlier quoted context omitted.
No, loop decrements rcx until it reaches zero and then stops
But rcx has not been initialised.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#84 mov rdx, rax
cmp rax, rcx
cmovg rax, rcx
cmovg rcx, rdxRe: Ask HN: What are some examples of beautiful x86 assembly code?
#85The first half is some fun writing with stock good advice for software development, and the second half is a bunch of code examples the author finds interesting, many of which are in various flavors of assembly.
(I have no affiliation with the author, publisher, nor any other ulterior motive. Office consensus is that this is the best book we've done a book club around - highly recommended as just plain fun to read, if you're already writing software.)
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#86http://finalpatch.blogspot.com/2014/06/dissecting-128-byte-r...
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#87Earlier quoted context omitted.
I was going to ask why? But then I read the single faq at the end: because I thought it would be funny...
In addition to being funny, it's appealing to me to have the option of generating assembly to perform a task in such a way that a human looking at the assembly would have enormous difficulty in determining what is performed. As suggested by its name, it serves as a nice obfuscator. It also fully avoids all branches.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#88The source code of AGC (Apollo Guidance Computer) written by Margaret Hamilton and her team. Clean and obviously it worked well. Comments are also interesting to read. https://github.com/chrislgarry/Apollo-11
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#89Earlier quoted context omitted.
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.
I think this is the biggest problem with learning x86 assembly (or ARM or anything else) on modern systems (or more specifically modern operating systems). 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 w…
Even in those "old" systems of single address spaces and no protection, you're constantly getting timer interrupts, interrupts for I/O, etc., which your application might not have installed its own handler for.
Re: Ask HN: What are some examples of beautiful x86 assembly code?
#90Earlier 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.
On your second question about different loops. First, you can loop through any register via (dec ; jnz ), thus having nested loops. Second, all valuable registers are pushed onto the stack and popped before/after a call or an interrupt, so their contents don’t change. Some registers have to be saved by the caller and some by the callee, depending on a calling convention and an actual usage. The stack is always available (rsp points to its top), so you can offload temporary values and concentrate on current evaluation, loading values on demand later.