Why I use assemblers

By paolo, 24 March, 2023

When I told some of my friends I had finished developing the Da Vinci Assembler, they all asked why on earth I still coded in assembly.

Here are a few reasons.

Because it is fun

Coding in assembly is fun. Once, many years ago, when I worked at Bellcore, a lady, who was an in house IBM rep, made this comment: "once you use assembly you do not want to use anything else". I could not have said it better. Coding in assembly is an act of freedom. No pesky C language railroading you on how to code. You do not want to use a stack?  No problem. You want to write a function with multiple entry points? No problem. Try that in C.

Because my code runs faster than the one generated by a compiler

An assembly program can always be made to run faster than an equivalent C program, except in a few simple cases when the two will be equal. This is the reason: optimization of a program is based on information that the programmer or the compiler have. The programmer will always have more information about the program than the compiler. Does the compiler know if two pointers might point to the same memory location? No, but you do. Does the compiler know which loops are CPU intensive and which are not? No, but you do.  The list is never ending.

Because it is easy to debug

When a program crashes in production, normally you get a memory dump from the customer, and little else.

When you get a memory dump of an assembly program, you get the truth.  You know where in the program the exception happened, the state of the registers, the CPU, and the memory. You also know exactly what the value in each register represents.  All that information will match one to one with what is in your assembly listing. To find the problem, in most cases, all you have to do is open your eyes.

With C, things are not so easy.  You can use a debugger, but how do you know if, at the time of the exception, the value of variable "i"  is supposed to be in register 13 or in its memory location? Use a disassembler? No, thank you. Reading an assembly listing is easy since it includes the original comments, and, hopefully, macro expansions. But reading the output of a disassembler and relating it to code written in C? My brain energy is better used elsewhere. 

So, should you learn assembly?

Assembly programming is not for everybody, but if you do not have any experience with assembly, you should give it a try. After writing your first program, and survive the frustration that comes with learning a new language, you will know right away if it is for you: with assembly it is either love or hate at first sight. But if it is for you, you will become a much, much better programmer in any language, and probably the technical leader in any team you will join.

Comments