Menu Share

Learning Assembly in the 21st Century

by | Published on
category Trendy

In this article I talk about the benefits of learning assembly as a “modern” programmer.

Table of Contents

Introduction

As time goes by more and more programmers are getting into the industry only learning high level languages and most them don’t and will never get into the details of how the low-level system works. But is it that much more different than learning a high-level language?

Well, yes and no. Machine code is the only code that the computer understands. Machine code is not readable by humans and is just a series of 0s and 1s formed into a sequence of bytes that cause the CPU to do stuff. Some time ago when computers were very basic you didn’t need anything else to be able to make the computer to compute stuff. CPUs essentially can do very basic stuff. They can modify bits of data – 0s or 1s. We combine those bits of data into mutliples making bytes. With bytes we can tell the CPU to make more operations like addition, mutliplication, subtraction, etc. Then someone invented the jump. Code is not always executed sequentially. Maybe in a calculator where buttons trigger operations. But code that executes without input or supervision you might want the so called conditions. Some code should execute in one case and other code in another case. Here is where the jump comes into play.

All these small operations form our assembly program. Assemyly is a language a little bit higher than the acutal CPU machine code. Assembly language is also highly dependent on the CPU architecture for which it is used. Or in other words you have flavors. This is why no modern programmer learns this low-level language. Everyone wants to write programs that execute everywhere without much change. And for that we have C and C++ and other even higher level languages.

Why is Assembly different?

Assembly is a language that has fewer constructs than other languages. It is stripped to the most bare programming model and this is to instruct the CPU to do stuff. These instructions include load memory address into a registry. Here you have to learn what a registry is – it is a storage inside the CPU. The CPU can do calculations within registries only. It has separate commands for loading into the registries or storing back into memory. Navigating in the code happens through jumping around the lines of commands. Then you can learn what jumps are executed when you have a while loop or an if check in your higher level language.

Essentially by learning assembly you would learn how to design a better overal programming model even in your higher level languages. There is a saying that designers work with constraints. We as programmers are also designers but not designers of a visual. We are designers of code. And we work with constraints every day. Our profession is essentially a creative one.

So assembly is different. It will give you a new more constraint perspective of your code. Having that you will learn new things and a new way of thinking and problem solving. Sometimes it is benefitial to reinvent the wheel (how many of you actually know how to make a wheel?).

Why should I care about Assembly?

Assembly is not for everyone. But I will make the point that if you’re writing code in a language like C++ that is not interpreted but compiled to assembly – then at some point in your career you should learn what is being generated for you by the compiler. Not that you can change the compiler itself… but you can change the code that you write in C++ knowing how it will be compiled into its assembly output.

Having this said there is one very popular website where you can learn what C++ gets compiled into and this is GodBolt. There you can check out if your ideas of what assembly gets compiled into are correct.

Where can I start?

Well there are quite a few courses out there. Most programming with assembly in our current times is either academical though or in embedded programming. You would rarely need to program assembly on a desktop and this is becaue people use very different desktops with various CPUs. This is why operating systems will abstract the machine info for a higher level language and would provide almost no tooling for assembly.

Having this in mind you should try to learn the assembly syntax for your current CPU and operating system since you have this device at your disposal. Usually for a desktop PC this would be the x86 architecture since this is what AMD and Intel produce. Compilers that support this architecture are NASM (mutli-platform) and MASM (Windows). You might also learn it through an emulator like this one.

If you have Laptop or a tablet though you can learn ARM assembly and this one is honestly better in my opinion. There are also emulators online or offline for this one though one of the best (and a bit harder) ways is to buy a board that is ARM based. ARM is used for embedded devices a lot – like the popular raspberry pi.

If you want to just understand the assembly language I would recommend a RISC based language though. Thse are ARM, AVR or RISC-V (emulator)

RISC vs CISC

RISC is an architecture for CPUs that means reduced instruction set – essentially you have less command options that you can give to the CPU. This makes it easier to learn and easier to execute. You have to write more lines of code for some operations but this actually results in low power, low memory and faster execution compared to the CISC architecture.

The CISC architecutre has been popular for desktop for a lot of time. Essentially the hardware manufacturers produce complex CPUs with a lot of possible commands that are produced by the hardware. This means that programmers have a lot of choice for which instructions to use and have some instructions that can execute in an “optimized” fashion with less work from the programmer. This makes chips more costly and they need more power and memory to execute.

So my recommendation is that you use a RISC architecture to learn the way the language generally works. But you will not escape the CISC architecture and learning commands for x86 since this is what C++ will compile your program into if you do desktop development.

Conclusion

I do believe that going lower level brings more depth of knowledge and might make the difference for the code that you start to write after learning Assembly. Assembly will bring you a more constrained environment where you will have to bring up more creativity to produce things. I highly recommend that you check this youtube channel out (not sponsored).

Leave a comment

Your email address will not be published. Required fields are marked *