Live data from Hacker News

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

news.ycombinator.com

81–90 of 93 posts

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

#81

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

That is a great resource. Another great example is a 16 byte paint program http://www.sizecoding.org/wiki/Paint16b

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

#82
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

Yes, I made the videos a few years ago. This video series is mostly for beginners as it goes pretty slowly.

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?

#83
post #26

Earlier quoted context omitted.

No, loop decrements rcx until it reaches zero and then stops

But rcx has not been initialised.

This is correct, from the snippet given - what the other commentators are failing to say is that they're assuming the registers are initialised "offstage" by some other part of the program.

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

#85
In my work book club we've been reading the book "zero bugs" by Kate Thompson.

The 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?

#87
post #58

Earlier 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.

No movfuscator post is complete without mentioning the demovfuscator [1]

https://github.com/kirschju/demovfuscator

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

#88
post #6

The 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

What are some particularly interesting parts of this poke around in?

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

#89

Earlier 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…

The whole point of how interrupt handling works is that it returns back to the same state of the program already in progress when finished. The abstraction is such that the interrupted program doesn't need to care.

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?

#90
post #31

Earlier 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.

Answer is you don’t have to initialize rcx, since it is already a prerequisite for a looping subroutine. There is no for (i=0; in is a counter and it is rcx itself. It is ‘discharged’ by a loop. If caller wants to save it, then it does that by his own means. This contradicts all regular languages’ rules, but this is low-level, far below all the safety.

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.

Post reply on HN