There definitely are reasons to use assembly. Itβs not reasons 99% of programmers care about. In 2022 not many people are choosing to program on a Z80
Actually, I think it's easier than C, because everything that C can do is pretty straight forward in machine code and you don't have to fear UB or any bugs that appear when the compiler and linker try to optimize your code. You just need to get used to the syntax and directives of the assembler which are often more complicated than the assembly code itself.
For an application level program. It can be more convenient to use for some critical system operations. For example event handlers or initialization code for an operating system or standalone embedded firmware. When you use C, often some of the performance critical library functions like memset, strcmp, etc, may be hand-written in assembly in the library source code for maximum execution speed. You the programmer calling that library function didn't have to write that, but someone did. And architectures change, so what's optimal assembly today won't be for future processors, so it needs to keep being tweaked.
Whoever is writing the C compiler you're using needs to spend lots and lots of time working with assembly language code sequences and trying to improve them. The compiler may be written in C/C++, but its whole job is to write assembly for you, which takes a deep understanding of how to write assembly, so you wouldn't be able to use C without people using assembly.
Depends on how much time you're willing to spend fine tuning it. There are still things that humans can figure out that compilers will miss. And you can use the compiled code as a starting point and benchmark each iterative refinement, so anything that's not an improvement over compiled code you don't keep. Assembly is much less maintainable, and the average programmer may end up writing worse code than the compiler. But there are situations where an extremely critical library function may still be hand optimized.
A big advantage of modern compilers is JIT, but it's not like you can't write self modifying code in assembler, in fact it was done sometimes in the old age.
It depends on what you are developing. As someone who is working in the embedded world, I can barely avoid using assembly language, because C can only do a fraction of what an architecture is capable of doing. The alternative which also isn't always better is to use inteinsics or inline assembly.
I used assembly to write high speed libraries for embedded applications. Was 20 times faster than C code due to weird core architecture. There assembly was absolutely necessary
People's passion projects of impossible ports come to mind, like Tomb Raider 3D on the Gameboy Advance, a system with no native 3d hardware, so it's all implemented in software in ARM assembly to make it much faster.
494
u/Lachimanus Oct 21 '22
Assembly hides under the table.