At university I have taken the compulsory course in Computer Architecture and Assembly Language Programming. I have found assembly language quite time consuming and hard to take grasp on. I still cannot understand the reason why assembly language is taught. I asked same question from my instructor and he smiled and said you will get to know in future. But I have a nature that I can't wait for so long for the answer once a question teases my mind. So I want to ask why do we still require assembly language if there are very powerful, fast and efficient programming languages and on top of that such languages offer wide variety of tools that make programming easy. So why?
One fairly good reason is all programming languages are an abstraction of how a computer works. In theory, for high level languages, the abstraction means that the programmer never has to worry about the details of the computer.
But the abstraction is always leaky, e.g. most (if not all) high-level languages don't automatically optimise very well for the CPU caches (e.g. cache-coherency and false sharing) and efficient multithreading is always tricky. This means that if performance is critical, the programmer might have to write their code differently.
The best way of getting the performance is by understanding how the machine works so that the programmer can do large architectural transformations that a compiler can't easily. As an example, making sure that threads process data in multiples of 64 bytes (to reduce false sharing on cache lines), or doing an array-of-structs ⇔ struct-of-arrays transformation.
Assembly (and C to some extent) is a really good way of learning these performance details, since it makes it really easy to understand exactly what the computer is doing because you control exactly what happens at each step.
(The leaky abstraction point also applies to accessing specific/custom hardware components.)
Machine code is still needed for key tasks, e.g.
Often, assembly language can be mixed into higher level languages, such as C, where assembly can be added inline to the C code.
That said, it is still a good idea to get a grasp of the underlying hardware architecture even if you will be programming in a high level language, as it will give you insight into how stacks, heaps, pointers etc work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With