Assembly as a First Programming Language

Programming languages, just as spoken language, are constantly evolving. They have come a long way since the era of punch cards and assembly language. We have low level languages, and high level languages. There’s functional languages and object-oriented languages. There are programming languages created specifically for code golfing, and there are joke programming languages such as Brainfuck.

With high level languages, such as Python or JavaScript, you can usually express your ideas faster than in a lower level language such as, say, C. So it’s a no-brainer that higher level languages are more widely used than low level ones.

High level languages have also gained adoption as educational programming languages, which, in my opinion, is unfortunate. That’s not to say I find languages like Python bad for teaching. But I do believe that there’s greater learning potential with assembly language — preferably one with a reduced instruction set.

My belief comes from the simple fact that high level languages are much more complex: the syntax and the feature set make for an overwhelming experience.

Take this piece of code in ARM assembly that prints a string that is stored in the .data section:

mov X0, #1
ldr X1, =thestring // stored in .data
mov X2, #6 
mov X8, #64
svc 0

Now compare it to printing a string in Python:


Clearly the Python code is much simpler at a glance, no discussion there. But what is print? You could say, “oh that’s a function that prints the string to the standard output”, and you would be right. But what is a function?

In the assembly code snippet, it seems like there’s quite a lot more going on. However, once you get past the preliminaries, it becomes glaringly obvious. It’s a simple system call. All you need to know is that stdout is assigned the file number 1 and it is opened for you by the OS. So we invoke the write system call, with the file we want to write to, along with the data we want to write. The magic disappears.

With assembly language, everything becomes evident, from variables to loops to functions to pointers — there’s no magic anymore. Most people won’t need to use assembly language in their day-to-day work, but everybody would benefit from the things you pick up as you learn it.


Liked this post? Enter your email to get the latest to your inbox.