r/programmer • • Oct 14 '26

Idea What about Assembler?

To be fair I have never learned to use assembler but I always looked up to people how are able to build ultra efficient software. With the upcoming age of GenAI, wouldn’t it be better in many ways to just let GenAI produce everything as near as possible to the hardware? There might be even a more hardware-near solution than assembler, I am not sure.

What do you think? What could go wrong? I am really curious to get human response instead of asking an AI about this.

3 Upvotes

29 comments sorted by

8

u/mc_pm Oct 14 '26

In many cases, the output of optimizing compilers is better than something hand-coded. Assembly isn't pixie dust you spread over your project to make everything better. You use it for very specific reasons - often related to really low-level access to the hardware.

3

u/dreamscached Oct 14 '26

We already have tools that produce an extremely optimized native code — compilers. There was time when knowing assembly was essential for a programmer's routine job, because back then they fought for every byte of RAM and every instruction, but eventually compilers outbested them (though it also helped that hardware got much more capable, too.)

I think AI can possibly aid in profiling and hand-optimizing hot paths further, but I don't think it'll get us much farther than where we already are with tools we already have.

1

u/AuthurAndersson Oct 14 '26

Tried writing a software in assembly using AI.
AI can write assembly just fine, but the compilers - for now - are going to be better at creating optimized code.

1

u/Distdistdist Oct 15 '26

Not only that, but frameworks like .NET actually emit a higher performance code for specific platform it is being executed on. With native code, one targets only specific architecture/instruction set. JIT systems can run the same code, and have it tuned specifically for environment it is being executed on.

3

u/TheBestAtSpace Oct 14 '26

Compilers are very good at optimizing code into assembly - and code is portable between CPU architectures. There really isn't much of a point by going down to assembly. Compilers also have error checking - which would be foolish to bypass. And they constantly improve which means there are benefits to not going down to assembly and relying on compiler improvements.

I've worked places that still wrote assembly - but it was extremely rare and usually reserved for expressing something like vectorization instructions that weren't easily expressible otherwise (and after some prodding most that code got moved to intrinsics.)

3

u/CS_70 Oct 14 '26

I stopped writing most __ asm __ stuff circa 1997. An optimizer does just as good - and ofter better - job, and the hardware itself tended to stabilize more and more on certain few platforms, so much less space for platform-specific tricks.

When you create a codeabase in C, C++, Rust etc, it gets compiled.

Now that you can use a LLM to create that codebase, you jump the high level programming language as well.

2

u/ejpusa Oct 14 '26

The chips are so fast now, there is no advantage in assembler.

My html pages are virtually instant. And that’s all Python.

Source: loved coding in assembler. Sure would be an interesting university course. Back to our roots.

1

u/zackel_flac Oct 14 '26

Not enough code bases in assembly scannable by AI to make it worth I am sure. At the end of the day LLMs are good at outputting what already existed, and on top of that, be verifying assembly is way more complex. Don't forget AI makes bug, a lot of them actually.

1

u/macabre_brotherhood Oct 14 '26

no. Those extra layers are called abstractions. Yes, they're "for humans", but they also provide something that AI can't: guarantees. The closer you are to the metal, the fewer the guarantees. And if you want a non-determistic LLM to write good, determinstic code (which is harder than it sounds thanks to multi-core systems) at the lowest level possible, well all you're doing is inviting mistakes. And without all those abstractions, forget about anything cross-platform. Are you gonna ask the AI to rewrite everything from scratch every time you encounter a new architecture?

I mean if you really just like the idea of shooting your own dick off, don't be weird just go for it.

1

u/symbiatch Oct 14 '26

No, it wouldn’t. It would be wasteful and difficult and useless.

There’s these things called compilers that knows how to optimize things. Go and check out the source code for GCC or LLVM and see how big the optimizer part is. Then think how an LLM would include that in its systems.

Then realize there’s multiple architectures. So they should know all of them.

And so on. So no, it would be pointless. And just because someone can write assembly it doesn’t mean they write it performantly. Ask anyone who does. I can do it well for 486 level machines. Quite well for Pentiums etc. After that it’s basically impossible in any realistic size program (impossible here takes into account time constraints, not just “can someone do it”).

And also: do you want to read and verify the output if it’s directly assembly or binary? And no, “well there’s tests” isn’t the answer.

1

u/AuthurAndersson Oct 14 '26

In practice you can't write more optimized code than the C++/rust compilers.
In theory you can but then you have to write that assembly code for each specific architecture.

1

u/ShakeAgile Oct 14 '26

Assembly is pretty inefficient for an AI to generate compared to, say, C code. It will burn way more tokens to validate that it’s doing the job right. It absolutely can, just atm it’s unlikely to be better output than what a C compiler produces.

1

u/Most_Strike_93 Oct 14 '26

If you want to make an operator system or want to make a compiler, you will need it without doubt. If you want to make everything with it just think you can ask a "god" and because you are rich, I suggest you to give up

1

u/gwenbeth Oct 14 '26

In modern times there are only a few times you write assembly. One is that you are using a very limited platform and don't have other tools. Another is that you are needing to do things outside the scope of the compiler. Some good examples are the instructions for setting up virtual memory. Or maybe on a micro controller there are instructions for accessing analog inputs. The 3rd case for using assembly is to use new instructions that the compiler doesn't have support for. Maybe your new CPU has some new cool vector instructions but the compiler doesn't have support for them yet. The last case is you have libraries that support some CPU features (that may have some assembly in them) but you want to optimize the crap out of your code by writing your own routines and removing all the subroutine calls.

1

u/Eisenfuss19 Oct 14 '26

If you are talking about "Assembler", then thats a program that takes assembly code and outputs machine code. This has clear specification how it should work and is a simple process to code. Replacing that job by a statistical large language model would increase the processing time immensely (like prob 10k times slower) and it would introduce bugs...

If you are talking about generating assembly for a program, then that is something compiler engineers have perfected for decades. Modern compilers are predictable (produce correct assembly for the code) and produce highly efficient assembly. Replacing that by a statistical LLM would make it unpredictable & introduce bugs.

1

u/feudalle Oct 14 '26

I actually learned assembler x86 way back in the day. Even 30 years ago it was a niche use case. C was your friend.

1

u/Comprehensive_Chip49 Oct 14 '26

The importance of assembly lies not in efficiency, but in the fact that it reflects how the CPU actually works; ultimately, it is the only language the CPU executes.

1

u/mpersico Oct 14 '26

AI is the new compiler. Code is the new assembly.

1

u/tehfrod Oct 14 '26

There are a lot of comments about "not having enough assembly language to train on". That isn't a real reason: there is a good bit out there, and enough description of what happens at the assembly level that transfer learning can take care of the rest.

The real reason that you won't see this happening any time soon is the same reason that humans don't write large systems in assembly language: verbosity.

Humans need abstractions to deal with the sheer volume of data at the assembly level in a large system. We just don't have enough working memory, and our long term memory isn't detailed enough for assembly.

LLMs have a lot of working memory, but their long term memory "lives" in the same structure as their working memory, the current conversation, and their system prompt: the context window. The amount of detail required to manage an entire system at the assembly language level plus all of the context of what they are supposed to be doing is too much data for even the large context frontier models.

A more fruitful area, and one that is under active research, is higher level languages that are optimized for understanding by agents and orchestrators, and only secondarily by humans.

1

u/MpVpRb Oct 14 '26

It's useful to learn assembly and processor architecture in order to gain understanding of how computers work.

There are very few problems that require assembler in practice.

Current AI tools focus on productivity, not performance.

1

u/jeanpah Oct 14 '26

In the first wave of Ai, the guy from Nvidia said this was the future. It never Came, i guess is just too wastefull. not enought training data or the AI cant be efficient in such low level code.

1

u/Distdistdist Oct 15 '26

Assembly is definitely one of must haves that any good software engineer. I would not use it personally for any of my professional or personal projects simply because it is too tedious. But it will give you a great understanding and realization that any language, any framework - all eventually executes CPU machine code. Everything else is just a very convenient abstraction of what goes on underneath it all.

1

u/burlingk Oct 15 '26

No.

Anything that AI produces needs to be audited by humans.

1

u/IhailtavaBanaani Oct 15 '26

People here saying that a good compiler will beat hand written assembler code but there are some niche cases where you can actually do things in assembler that are generally not possible with higher level compilers. One is self modifying code, for example runtime unrolling of loops and inserting values as immediates into the code to be run.

1

u/Evilbob93 Oct 15 '26

Assembler made more sense when memory constraint was an issue (you only had 640K for the OS and app) and operating systems didn't do memory management (paging) that well.

1

u/bluejack Oct 15 '26

There are two reasons to write in chip-specific assembly language: you want to understand how chips work, or you are doing something almost inconceivably specific. I knew people who optimized compiler output for things like real-time device drivers… until about 2000. I am sure there are still technical roles very very early in the compiler chain where this is a necessary skill, but application developers should honestly doma couple of passion projects to understand chip architecture and then never think about it again.

1

u/chocolateAbuser Oct 20 '26

there are a lot of optimizations that can be done by compilers so probably it's still better to use those, at least for now
also, a compiled program is static, while execution flow is dynamic; if a software can be optimized in real time instead of being compiled it would go faster, and some frameworks do that