Let's Learn x86-64 Assembly (2020)
38 comments
·July 13, 2025urda
It's always a great way to get a better understanding of things but at least just poking around assembly a bit once. You do not have to make a project or anything big, but do not be afraid to check it out.
gnabgib
(2020) Discussion at the time (180 points, 38 comments) https://news.ycombinator.com/item?id=24195627
nice_byte
Author here. The final part of this series is still sitting in my drafts.
It was nominally supposed to be about flow control instructions, but as it goes with those things, it spiralled and ended up touching on relocations, position-independent code, aslr... One on these days I'll clean it up and post it
90s_dev
Please do!
pm2222
>> Additionally, the higher 8 bits of rax, rbx, rcx and rdx can be referred to as ah, bh, ch and dh.
Did you mean “ax, bx, cx, dx”?
ordu
ax, bx, cx, dx are 16 bit registers referring to the lower 16 bits of rax, rbx, rcx, and rdx respectively. Bits 0..8 can be referred as al/bl/cl/dl, bits 8..16 as ah/bh/ch/dh.
wunused
It's ambiguous, but I believe the comment you are replying to suggests that the sentence should read:
>> Additionally, the higher 8 bits of ax, bx, cx and dx can be referred to as ah, bh, ch and dh.
anamexis
Those would be the lower 8 bits, no?
wunused
In a 64 bit register, e.g., RAX, AL refers to the lowest 8 bits [0-7] and AH refers to the next 8 bits [8-15].
Together, AX refers to bits [0-15]. EAX refers to [0-31].
It's counterintuitive (or at least, inconsistent) that we have a name for bits [8-15] but not for [16-31] or [32-63]. My fuzzy understanding is that this came about from legacy decisions.
This page has a helpful visualization at the top: https://www.cs.uaf.edu/2017/fall/cs301/lecture/09_11_registe...
grg0
It's neither. al is the lower 8 bits of ax (ah the higher 8 bits). ax is the lower 16 bits of eax. eax the lower 32 bits of rax.
Here's the AMD manual: https://docs.amd.com/v/u/en-US/40332-PUB_4.08
pm2222
ax=ah:al eax=?:ax rax=?:eax
vivzkestrel
Spectacular post, are you planning to add sections on reverse engineering executables because this definitely looks pretty close
nice_byte
(i am the author) not to this series, but the very first post on the blog is an example of a simple reverse-engineering exercise: https://gpfault.net/posts/ripping-sprites-from-super-cyborg....
pjmlp
Thankfully Intel syntax.
Cockbrand
Now I'm curious - what other syntaxes are there?
pjmlp
The other one, is a clunky one from UNIX world point of view on x86 CPUs, follow the links on the sibling comment.
Rather clunky and most UNIX Assemblers were never as powerfull as other systems macro assemblers, since after UNIX System V, it was there only as an additional external tool pass for the C compilation steps, and even before that, the assembler was quite minimalist.
Then there is the whole brain twist of being used to op dest, src, and having to switch into op src, dest.
I prefer the Intel approach as it is more similar to dest = src, rather than src -> dest.
Intel's approach is also more common across various assembly languages.
90s_dev
I came to the party way to late. A month ago, I found out asmjit was a thing, and now it's happily embedded in my app. But I don't know assembly! I tried to learn a few times since the early 2000s but the timing was never right. But hand written asm as a feature fits perfectly into my upcoming app, so now I am on a roll learning assembly! Here are some more resources I found so far:
https://news.ycombinator.com/item?id=22279051
https://sonictk.github.io/asm_tutorial/#introduction/setting...
https://cs.brown.edu/courses/cs033/docs/guides/x64_cheatshee...
https://people.freebsd.org/~lstewart/articles/cpumemory.pdf
https://learn.microsoft.com/en-us/cpp/build/x64-calling-conv...
enjoytheview
Here's a really good free one:
OpenSecurityTraining2 Architecture 1001: x86-64 Assembly
https://p.ost2.fyi/courses/course-v1:OpenSecurityTraining2+A...
They also have RISC-V and many other for debuggers and reverse engineering tools (ida/ghidra for example)
Asm2D
I think AsmGrid has a great overview of X86 and AArch64 instructions:
- https://asmjit.com/asmgrid/
mananaysiempre
For x86 encodings, there’s also http://ref.x86asm.net/index.html and of course the venerable https://sandpile.org/.
rfl890
Felix Cloutier's page has always been my go-to
__alexander
I haven’t seen this site before. Thanks for sharing it.
electroglyph
wow, that's great. thanks for sharing!
Razengan
I wish there were more articles and resources about modern ARM assembly. Not that I ever will or have programmed in Asm, but I like learning about it and imagining I will, and Intelisms feel so archaic and crusty in comparison.
WalterBright
I'm learning AArch64 assembly in the process of writing a code generator for it. godbolt.org is a great resource for "how do I do this?" Write a short function, run it through godbolt.org, see the instructions generated, lookup the instructions in the spec:
https://www.scs.stanford.edu/~zyedidia/arm64/encodingindex.h...
It'll be my keynote presentation at the D conference next month.
throwaway31131
https://shop.elsevier.com/books/computer-organization-and-de...
It's currently 50% off and not only will you learn ARM, and some history about ISAs in general, but you'll learn more about how the computer itself works.
And if ARM isn't a hard requirement, an older edition that uses RISCV as the core ISA is a free download.
https://www.cs.sfu.ca/~ashriram/Courses/CS295/assets/books/H...
Highly recommended.
slashtom
I learned on the MIPS processor, computer organization / architecture one of the most challenging CS courses for me. I don't remember much but I definitely remember the mips pipeline...
pmxi
The first link was the textbook I used for my computer architecture course last semester and I concur. This was the first time our professor taught ARM instead of x86_64 because he believes ARM is the future.
lauriewired
This is my own channel, but I made a 10+ part series on modern ARM assembly you may find interesting. I used CPUlator for the demonstrations, which is a nice way to inspect the memory as well as the individual registers as you are running a program.
All runs in the browser:
https://youtube.com/playlist?list=PLn_It163He32Ujm-l_czgEBhb...
spauldo
Any reason for ARM specifically? There are a lot of microcontrollers out there that fairly simple but without Intel's crustiness. Atmel, for instance. And if you decide to actually try experimenting with them you can get yourself set up for it for less than $100.
90s_dev
The first HN link in my comment addresses that. The short version: learn the earliest asms first, then progressively learn the newer ones until you get to today, and none of the knowledge will be wasted. Kind of like fast-forwarding.
mjevans
I wouldn't say you are wrong, but I would also postulate.
The smallest, simplest, 'useful' (in terms of useful enough that lots of devs did good work with it and thus it might also be 'popular') ASM sets are probably also sufficient to start with. Provided you've got a good guide to using them, and also ideally a good sheet for why given instructions are packed the way they are in binary.
I do agree you're more likely to find pointers to such resources in more classic architectures. They're also more likely to be easy to find free copies of useful literature.
throwaway31131
I'm not sure how "useful" or "good" the work is. But some one instruction computers have a considerable amount of tooling already in place.
i.e. https://esolangs.org/wiki/FlipJump
Flip Jump is amazing. I understand the theory and how it works but it still amazes me that it does. Things like this is why I love the science in computer science.
And subleq even has a c-compiler and operating system, just wow. https://en.wikipedia.org/wiki/One-instruction_set_computer#S...
mixmastamyk
Let's learn RISC-V assembly!
- https://en.wikipedia.org/wiki/RISC-V_assembly_language
- https://asm-docs.microagi.org/risc-v/riscv-asm.html
dapperdrake
AArch64/Arm64 assembly:
null
I wrote one: https://www.nayuki.io/page/a-fundamental-introduction-to-x86...