NHacker Next
  • new
  • past
  • show
  • ask
  • show
  • jobs
  • submit
The Art of 64-bit Assembly (nostarch.com)
skippyfish 2 hours ago [-]
I know that we're discouraged from meta-comments, but what is going on in this thread? It's a nearly 800-page book about the art of programming. A huge amount of work on a topic that should be dear to our hearts. News for hackers, right?

But somehow, the discussion has three themes. It's 50+ comments of "I don't like the first sentence of the marketing copy", "I don't like the tool the author is using", and "what would happen if we train an LLM on this book?". Has anyone read the sample chapter? Did you like it? Anyone here owns volume 1 and has opinions about that?

lexicality 16 seconds ago [-]
I own volume 1 and when it first arrived I dropped it on my foot and had to go to the doctor. I have not got around to reading it again. His original x86 ASM book was good though.

I also read his Write Great Code series and generally found it to have some pretty good advice, but it was also full of things like recommendations to never trust compilers and to write lots of arcane unreadable magic code to unlock ultimate speedy hacker cred.

That being said, if you want to learn about ASM in TYOOL 2026 then you could do a lot worse than learning it from someone who doesn't trust compilers and does everything themselves.

mathisfun123 26 minutes ago [-]
this is what almost every hn post is: lowbrow reflexive/reactionary responses. it's been like this for years. try to call it out and you'll be censured by dang or one of the other police officers for being "uncharitable" or something like that <shrug>
roundwego 2 hours ago [-]
[flagged]
MaskRay 36 minutes ago [-]
Interesting to see that people are still spending much time on assembly languages :) I've had a lot of fun with it in recent years as well. (Shameless plug: I've written a few on LLVM integrated assembler regarding better fragments and improving expressions and relocations).

When comparing GNU Assembler and MASM, GAS is missing many features: while loop, string processing (.e.g strlen)

> page 3: "It’s important to understand that MASM converts macro invocation arguments to text values before doing the macro expansion"

Like MASM, GAS uses call-by-name evaluation by default. While GAS's altmacro mode does allow for expression evaluation using syntax like `%(1+2)`, it has strict limitations: it only supports absolute expressions and is restricted to argument positions.

In contrast, MASM's % operator (page 8) looks far more general.

tensegrist 5 hours ago [-]
i'm sorry, starting with "you can ask AI to … [but it'll do an incomplete and bad job]" and then launching forth into a hundred words of AI-produced text is not very appetizing

i hope this is the publisher's fault and the author replaces it with something decent of their own. contrary to the opinions i've heard around (including elsewhere on this thread) learning asm is still meaningful today and it's something i'd like to get better at so i will consider getting this book or one like it once $work is a bit less hectic

asibahi 3 hours ago [-]
This text doesn’t seem AI generated to me.
boondongle 3 hours ago [-]
We've really gotten to the point that certain styles seem AI generated in many cases because many folks are poor writers and anything past a high school level is difficult for them. I'm not speaking in this case specifically, just in general.

It's also one of the reasons its insanely popular in ESL countries and frustrating/disliked in English-speaking countries because it makes things easier in one and harder in the other.

It was never the goal, but it is the reality. The same style people call AI, was often called being a pedant or being wordy 10 years ago.

asibahi 2 hours ago [-]
This publisher copy is neither pedantic nor wordy. It is just a market blurb for the book.

The thing that frustrates me the most about AI is how every thread in every forum spend half the time arguing whether an article is AI or not, as if bad writing only started to exist with AI. Just fucking don't read it.

Someone 5 hours ago [-]
Weird title for a book on assembly

- for x64

- on Windows

- using MASM

There are other 64-bit OSes, CPUs and assemblers for them, and people do use them.

agarren 2 hours ago [-]
What a weird, low-effort comment.

Randell’s got another (large) book on ARM assembly. He’s also got a handful of other great books on software engineering in general - he’s more than aware that “there are other 64-bit OSes, CPUs and assemblers for them, and people do use them.”

This particular title, “the art of assembly” has been around for a while. This x64 version is the latest iteration - it’s a great book compared to the previous version which introduced and focused on “high-level-assembly”, basically a collection of masm macros that effectively constituted a small language.

It’s fair to say that anyone even remotely interested on x86/64 assembly is aware of AoA.

leoc 2 hours ago [-]
It's the result of seeking to maintain consistency with the titles of the previous books in the series. And while the platform coverage this time is very narrow, any book on assembly in general is going to have to pick some specific platforms and hope that the reader will be able to transfer the skills acquired to others as necessary.
Retr0id 3 hours ago [-]
If you're actually writing software in assembly (as opposed to merely optimizing hot functions in an otherwise high-level codebase), in my experience MASM is the most pleasant tool for the job.
b5n 2 hours ago [-]
The most pleasant is the one you're most familiar with. I still use gas with at&t syntax.
Retr0id 2 hours ago [-]
MASM's niceties go far beyond just syntax, though
tengwar2 5 minutes ago [-]
I last used MASM back in about 1989 (with MS C on OS/2 1.0). Do you have any hints on how it has changed since then? What is nice about it, and why does the debugger not match up to CodeView?
3 hours ago [-]
woadwarrior01 2 hours ago [-]
Wow, I can't believe that the author is still updating the book! I'd learnt protected mode assembly from an older version of this book, decades ago. And IIRC, there was an even older 16-bit version of the book back then.
Retr0id 6 hours ago [-]
> what Windows actually expects the vtable to look like

I'm not a Windows-knower, are vtable layouts part of the user<->kernel ABI?

jcranmer 4 hours ago [-]
All of the major kernel ABIs are using C function interfaces as their stable ABI (except Linux, which uses an assembly syscall instruction as the stable interface, although you still rely on a lot of the ancillary C ABI for things like struct layout or stack layout).

For C++ ABIs, there are really only 2.5 major ABIs: the MSVC ABI, used by MSVC and clang wanting to be compatible with MSVC, and the Itanium ABI, used for everything else. There are some slight variants on the Itanium ABI which makes the ".5": ARM uses a different layout for exception handling tables, and there are some flags you can set to use a more compressed vtable layout (32-bit offsets instead of 64-bit pointers). (There are other older ABIs, but either companies stopped making a C++ compiler or they switched to Itanium.)

Windows COM APIs (which isn't part of the kernel, they're still userspace libraries) rely on an IDL which is meant to be directly compatible with the C++ vtable. That said, they also use a restricted subset of C++ that all of the ABIs are going to agree on for vtable layout--if you don't overload any functions, and you don't have any virtual inheritance, there's pretty much only one possible sane vtable layout, and everyone does that.

masfuerte 2 hours ago [-]
Being pedantic, the COM vtable layout is defined independently of C++. The Windows headers used to (and maybe still do) have macros that could declare COM vtables as explicit structs so you could use Windows COM interfaces from C.

That used to be the case anyway. It's possible they binned the C support in the switch to 64-bit. I haven't looked since.

invokestatic 5 hours ago [-]
It’s part of the MSVC x64 ABI, not a part of the kernel ABI. The kernel and user mode (Win32) APIs all use C linkage so vtables are not relevant and the ABI is a convention of the compiler not the OS. Practically speaking though if your software runs on Windows it will probably use the MSVC ABI.
Joker_vD 5 hours ago [-]
Last time I checked, software compiled with both Cygwin and MSYS2 internally uses SysV calling convention, only switching to WINAPI when calling, well, Win32 API.
boguscoder 6 hours ago [-]
Yes, you either follow Itanium ABI (non Win) or MSVC ABI. Technically nothing stops _your_ compiler from implementing totally own conventions but it will only be compatible with itself
Joker_vD 5 hours ago [-]
GHC uses its own calling convention yet it's compatible with Win API just fine. The secret, of course, is to implement not only your bespoke calling convention, but also the other ones that you care to interoperate with.
rajeevk 5 hours ago [-]
>> You can ask an AI to explain how vtables work in x86. It will give you something that sounds right. What it won’t give you is what Windows actually expects the vtable to look like, why method dispatch behaves the way it does at the instruction level, or what breaks when you deviate from convention. This volume of The Art of 64-Bit Assembly closes the gap between a plausible explanation and genuine understanding.

Once LLMs are trained with the content of this book, then this statement will no longer be true.

If this book becomes even a bit popular, these LLMs will get access for sure to the content of this book in their next training.

fasterik 4 hours ago [-]
I'm skeptical of that statement to begin with. I would be surprised if models weren't trained on plenty of x86 and Windows internals information. If nothing else, they could be prompted to download the relevant material and then write well-commented source code to explain the implementation details.

This reads more like marketing copy targeting anti-AI sentiment than anything.

adamddev1 4 hours ago [-]
One book probably doesn't do it. I know the LLMs have been trained on one particular book that explains some crucial things about the grammar of a low-resource language. The LLMs will sort of use the information, terms, and concepts in the book to explain things but they fail to understand and continue to confidently mangle the language and plagerize the content of that book.
jagged-chisel 5 hours ago [-]
But will they prioritize this information over what they have currently, or over their own hallucinations?
mdp2021 5 hours ago [-]
> Once LLMs are trained with the content of this book

I strongly believe that the "future" should be LLM+Corpus - something beyond LoRA or RAG or context, but what we need and will have will be a generally strong LLM augmented with the most proper learning from the "selected library of relevant material".

And in parallel, also the reasoner over the corpus will be implemented (something that properly studies, not just reads, and achieves the pinnacle of reflection over the corpus).

f3abfeca54812 5 hours ago [-]
Are you saying that people should then write books for LLMs only so that you can query them to get the summarized answer and not pay for the book?
mdp2021 5 hours ago [-]
I cannot get a faint idea about how you managed to get such a twisted misunderstanding.

Let us reformulate through the framework: the learned wrote books; the learners read them books, as many as possible in a ranked list; we may one day achieve automated learners; learned learners are our consultants; we benefit from the level of learning of them consultants; we would benefit greatly from the Perfected Learner; I gave a few lines of the general directions towards "thinking of them in view of building them" in the post above...

astrange 4 hours ago [-]
Given the tricolon in that text, I think the content of the book may have come out of an LLM.
oinoom 5 hours ago [-]
You also don’t need it to be trained on it specifically, just give it some docs or links to docs or source code as reference
slashdave 4 hours ago [-]
Show it the disassembler...
f3abfeca54812 5 hours ago [-]
But even then your prompt has to be explicit enough to get that answer and not the 'wrong one'. Of course they will prioritize stuff that is more often in the training data. That's why AI will be a dead end long term
csense 5 hours ago [-]
I'm sorry, MASM? All the cool kids use NASM or YASM.
mdp2021 5 hours ago [-]
Some still like FASM. Why NASM or YASM?
sureglymop 4 hours ago [-]
I prefer FASM but NASM is a strong second choice. But at the end of the day it really doesn't matter.. purely preference.
sitzkrieg 4 hours ago [-]
fasm absolutely rules on windows
ndesaulniers 4 hours ago [-]
The Linux kernel prefers GAS (or clang) w/ the C preprocessor. Luckily most of clang's assembler unit tests (and LLVM's MC layer unit tests) also use GAS style syntax.
rramadass 4 hours ago [-]
Related;

1) All Assembly/C++ books by Daniel Kusswurm.

2) Low-level Programming: C, Assembly, and Program Execution on Intel 64 Architecture by Igor Zhirkov.

sylware 4 hours ago [-]
I am more curious about how they would cleanly manage hierarchical labels (usually called "namespaces"), register naming, and stack management with deep register spilling, description of the register state on the various entries from the various dominators of a code block.

I am doing all that with a basic C pre-processor in my assembly source code. But the more I think about this, the more I think I should write my own pre-processor, which "should" be much simpler than a C pre-processor in the end and would do a cleaner job since taylored for those usages (the "annoying" thing is the arithmetics expression evaluation).

I would write this pre-processor in assembly, namely design a binary specification (that to be ready for other ISA implementations).

Then, they are the really important things: for all micro-architectures, how to be friendly to conditional branch predicition, how to handle BTB entries layout in a cache line, show how important the "cache line" is ubiquitous, etc.

I remember clearly one of the TheHeavyThing developers telling me than with a basic and naive hand compilation of gzip, he was beating the best compilers, at that time, by a consistent 10/15%. Let me remind people here of something: nobody is supposed to be able to beat a compiler on deep and hairy compilation units. If it is the case, something is wrong in that compiler.

slashdave 4 hours ago [-]
I'm... confused. Don't we use macro assemblers anymore?
sureglymop 4 hours ago [-]
We do. I always use fasmg and it's amazing!!
sylware 4 hours ago [-]
fasmg[12] is much more powerful than gas or nasm(~yasm): it is not a classic pre-processor. With CALM, it is basically a language able to implement assemblers supporting various binary file formats.
sylware 4 hours ago [-]
The pre-processor of an assembler is specific to that very assembler.

For instance, with a C pre-processor, I have a very lean C pre-processor dialect which allows me to assemble simple x86_64 code with... fasmg[12] or nasm(probably yasm) or gas(intel syntax).

A big project which was bitten by specific pre-processor abuse: ffmpeg with nasm (but it is still much less toxic than to start to be hard dependent on advanced and specific C compiler extensions... look a the failure from linux on that matter).

EtienneDeLyon 6 hours ago [-]
[dead]
norir 5 hours ago [-]
If you need better performance than a higher level language affords you, I would not recommend programming directly in asm. Instead, I would write a compiler. Raw asm is seductive since the start up cost is relatively low. You can get started in an afternoon. The trouble is that writing correct assembly is much harder than high level code. You have to hold in your head the register state at all times. You have to know if the function you are calling will clobber registers that you need after the call and manually save/restore them. This will slow down your velocity and the resulting code will be long and difficult to read. It will also rely on a lot of undocumented information that only resided in your head while writing and has since been evicted. Good luck debugging a program written in assembly that no one has looked at for two months.

On the other hand, if you write your own non optimizing compiler, you can avoid a lot of these problems by, for example, tracking what registers a function writes and ensuring they are saved before a call and restored after. Then you can actually get the raw performance of handwritten asm without the pitfalls (the resulting code would still he harder to read and maintain than equivalent high level code, but at least it would be tractable). Even better, you can write your own high level assembler that is actually portable to other architectures. For example, instead of directly modeling x86_64, your compiler can model a cpu with 16 general purpose registers and a set of instructions that map to x86_64 instructions. An arm port would be straightforward since arm also has 16 general purpose registers and you can model x86_64 instructions as one or more arm instructions (and you have extra registers for x86_64 instructions that must be modeled as multiple arm instructions). Or you could do the reverse and model 32 general purpose registers using arm instructions and use predefined memory slots as virtual registers on x86_64.

amelius 5 hours ago [-]
Is anyone still writing assembly in the age of LLMs? Asking seriously because most assembly is just doing one very simple thing very fast and because it's so simple conceptually, an LLM can easily code it without errors.
sousousou 5 hours ago [-]
Yep. In my experience, LLMs easily go in circles with even simple assembly, creating fixes that result in 2x slower code and then fixing those with even slower code. They are pretty great as a reference or finding needle in the haystack bugs though!
derefr 3 hours ago [-]
Is that with or without the LLM being able to assemble + profile its hypotheses itself? Because “optimize this code to execute in fewer CPU cycles under the test harness” seems like one of those perfect self-contained problems for LLMs (their equivalent of an “embarrassingly parallel problem”: an “embarrassingly-easily-explored solution space with embarrassingly-easily-measured objective success criteria.”)

Sure, they might make all sorts of dumb hypotheses at first, but as long as the results of those stay in their context, they do seem to eventually “run out of ways to be stupid.” (Which is to say, LLMs seem to experience in-context learning even via self-directed trial-and-error, if given a sufficiently-large number of iterations and no way to cheat.)

ndesaulniers 4 hours ago [-]
I was able to use Claude to translate a few thousand lines of assembler from one syntax+toolchain to another. Process was definitely iterative; had to keep adding a few rules along the lines of "don't do this...here's the equivalent pattern." But in the end it did a good job and saved me a ton of time. Allowed me to move a ton of unit tests off a hand rolled broken+bad assembler to a modern production toolchain.
rescbr 1 hours ago [-]
This is definitely not my experience with GLM-5.2. It is writing pretty good ARM SIMD code.

It also is an excellent radare2/rizin/ghidra driver as well. Maybe it's because its ~cyber~ capabilities (pretty much linked with assembly-level knowledge) aren't guardrailed off?

stevekemp 3 hours ago [-]
I wrote a lisp compiler recently, and that involved generating assembly language.

My output is linux/amd64 assembly language which is compiled by nasm. I don't link to glibc, so I had to implement my "print int", "print string", and similar primitives in raw assembly.

I successfully implemented a stop&copy garbage collector, and other interfaces to the OS such as reading command-line arguments, environmental variables, and so on. All in assembly. Though my compiler is written in golang the runtime, and all supporting functions have to be in assembly to make sure that the binaries it produced are static.

(I wrote a lisp interpreter which can be compiled, and which can be used to run itself, so I got an indirect REPL.)

amelius 1 hours ago [-]
An efficient concurrent garbage collector would be something I would buy a book for. (In fact I have one GC book on my bookshelf).

But assembly? I'm not sure, honestly. Architectures change, and you can easily converge to good code by talking to an LLM.

May I ask why you didn't use LLVM as a target?

emptybits 5 hours ago [-]
I'm not being flippant but I think part of your answer is in the first two words of the title.

IME while LLMs may help delivery utility in a finished work, humans often value the absorption, mastery, style, or constraint of performing a mundane activity hands-on and brains-on.

sureglymop 4 hours ago [-]
Yes. Mostly for learning purposes and for fun. Also, there are things you must drop down to assembly level in order to achieve. Implementing coroutines, a JIT compiler, etc. It's fun to learn about these.
mdp2021 5 hours ago [-]
> Is anyone still writing assembly in the age of LLMs ...

Yes. Its "simplicity" is exactly why we pick and assemble piece by hand - we imagine the leanest way.

LLMs are (not just in Assembly, but especially) very precious as a natural language manual.

> an LLM can easily code it without errors

One day it will probably also be able to have sex, and yet we think we will not pass on the experience - unless, like some kind of coding, it will be a "strictly professional only for money" operation (like in Monty Python's Argument sketch).

Edit: as esteemed emptybits wrote above, rephrasing: it's /the Art of/ Assembly.

alain94040 4 hours ago [-]
> Yes. Its "simplicity" is exactly why we pick and assemble piece by hand - we imagine the leanest way

Professionally, assembly is the last thing I would let an LLM generate for me. That's because if you need to write something in assembly, it's because it's critical: operating system context switch, interrupt handler, that kind of thing. You don't want to be 99% correct, you need that code to be 100% good.

I can imagine some other professional scenarios that I'm less familiar with, where you want to write a tight numeric loop of NEON64 assembly and let the LLM do it, because it's frankly a pain to do by hand, and you can test it to some degree of confidence.

breckinloggins 4 hours ago [-]
Yes. And for the same reason I still write in C or Common Lisp - by hand - in the age of LLMs.

It’s a hobby.

eat 5 hours ago [-]
You could've also asked if people still wrote assembly in the age of compilers, and the answer would be the same. Sometimes we want/need to control or understand what is emitted by the tool.

However, I want to point out the obvious fact that people are still playing the piano in the age of the self-playing piano. Humans are experiential creatures, and we enjoy a wide range of activities for their own sake that may have nothing to do with efficiency of output.

WalterBright 5 hours ago [-]
I do now and then, for bits of code that is not expressible in the language. Things like special instructions, or special fixups.
sitzkrieg 4 hours ago [-]
yes, i write c and asm professionally for small hard real-time mcus. llms give me wrong code nonstop in what little i have tried in my field. not a force multiplier
root-parent 3 hours ago [-]
>> an LLM can easily code it without errors.

An LLM knowns nothing of the taste of ginger.

Keyframe 5 hours ago [-]
an LLM can easily code it without errors

can't tell if sarcasm or not. Just in case it's not.. in that case why don't we all vibe everything in assembly? No need for abstractions anymore since that's a human concept. LLM can do it without errors, as you say, and we'll reap the benefits of speed!

mdp2021 5 hours ago [-]
> why don't we all vibe everything in assembly

I really loved this retort, but we have to reply: from that cone of perspective, it would be probably better to "vibecode" in C and not hope that the LLM does a better job than the compiler (for efficiency, not for absence of bugs as per the original). (Edit: for clarity: some compilers of low level languages are specialized in ASM optimization - the LLM will hardly beat them.)

fragmede 5 hours ago [-]
Because it's not portable. The world we find ourselves in is at least x86 and ARM, and assembly for one isn't good for the other. LLVM has a hardware agnostic intermediate representation (IR) that one could use though.
Keyframe 3 hours ago [-]
you're not thinking vibe enough. Your prompts are now the program, that's your abstraction. Ideally, if it would work, LLM would be the one then producing each platform's output. Maybe even compiling from higher languages to gather some compiler optimization hints and then doing full salvo of asm. Ideally.
slashdave 4 hours ago [-]
Except for some odd corner cases, it is very hard for a good engineer to beat compilers these days (they are very good now). Not to mention, tuning depends on the platform, and often the exact model of chip.
Keyframe 3 hours ago [-]
* it is very hard for a good engineer to beat compilers these days (they are very good now).*

I keep hearing this for the last 20 odd years, yet I see evidence to the contrary each and every day. It is hard and honest work though.

zero-sharp 4 hours ago [-]
there were two lead developers from FFMPEG on Lex Fridman's youtube channel who talked about performance gain from assembly. They claimed the opposite

https://www.youtube.com/watch?v=IUo0UwZOaRw

slashdave 3 hours ago [-]
Yeah, a corner case (streaming) and good developers working very hard.

The original SSE (SIMD) extensions were actually written with this use case in mind. When they first came out, the compilers were awful. They've since caught up.

3 hours ago [-]
Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact
Rendered at 21:11:10 GMT+0000 (Coordinated Universal Time) with Vercel.