Learning Lower-Level Programming Languages

Ironically, this article is a high-level approach to programming at lower levels. I’m not saying that it’s the only approach, but it’s an approach that works for me.

First of all, what are language levels?

Low-level Assembly Language does not include a method to display text on your screen; you have to develop that functionality first. While mid-level C does include such functionality, there’s still a little work involved. Meanwhile, high-level Python provides that functionality and handles that extra work for you.

Simply put, lower levels leave much of the work for you to do while higher levels handle increasingly more on your behalf. Higher-level languages therefore allow you to focus on such things as algorithms and user interface design without worrying about such things as memory management and computer architecture. At lower levels, you need to concern yourself with all that and more.

If it’s harder, why bother writing code at lower levels?

A car with a manual transmission can outperform a car with an automatic transmission in such areas as acceleration, fuel efficiency, and the costs of maintenance. They’re cheaper to buy, too. Notwithstanding I’ve seen drivers shift gears while both eating and drinking, it’s unquestionably easier to just shift your car into “D” and turn on the cruise control.

Programming is no different. Taking control of your hardware can measurably boost performance. While you can argue that a calculator app is sufficiently quick enough to not have to worry about fractions of seconds, performance matters when your runtime is measured in minutes or hours.

Optional step 0: learn a high-level programming language

Some concepts, while differing slightly, carry over from language to language. Variables are variables are variables. Constants are constants are constants. Functions are functions are functions. And, so forth.

Learning these concepts and putting them to use in higher-level languages could conceivably be easier than jumping right into lower-level languages. You can master the basics before potentially struggling with more advanced concepts. For example, you can learn how to assign a value to a variable and master that before learning about variable types and declarations.

Step 1: learn the C programming language

I’m sure there are other choices out there, but I’m more familiar with C and will therefore use it for my example. Despite its power relative to higher-level languages, you can get started with C fairly easily. In fact, you’ll typically learn the basics first and discover that you can write programs without using any of the language’s advanced features.

For a quick start into C, I recommend the SoloLearn app. It doesn’t get into advanced concepts; it only shows you how to wield C similarly to higher-level languages. I also recommend the book The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie. The book advances beyond the app, but appropriately covers the basics first.

Step 2: learn how to boost performance with C

The aforementioned book gets into more advanced topics such as pointers, pointers to pointers, and so forth. If you read it, you’ll notice mentions of performance-boosting code. For example, it shows you how you could reference arrays one way, similar to higher-level languages, or you could reference them another, quicker way that doesn’t exist in higher-level languages.

The best place to ask questions and seek answers seems to be the r/C_Programming subreddit. I’ve received answers that are noticeably more advanced than what the book covers. Code suggestions also tend to work on the first try, which is often not the case elsewhere. That’s just from my personal experience; feel free to have your own preferences.

Step 3: learn an Assembly Language

I don’t think of Assembly is a language at all, but rather a collection of dialects. The fact that there is no one language can add considerable confusion when you’re just starting out. You can find a plethora of code across the Internet that just won’t work because it is either a different dialect, or it’s for a different computer architecture, or it’s for a different operating system. I even have an entire book that is of virtually no value because I don’t use its dialect.

Speaking of books, my favorite book thus far on this subject is PC Assembly Language by Paul A. Carter, but keep in mind that this book covers the NASM dialect. You’ll want to find a book specific to your chosen dialect, hardware, and operating system. When (not if) you have questions, I’ve found value in the r/asm subreddit. I’ve tried the r/nasm subreddit, but it seems too small and too inactive. Other dialect-specific subreddits may or may not respond the same, in which case I recommend defaulting to r/asm.

Baby steps

I think of this guidance as baby steps downward. First, we assign a value to a variable, for example. Then, we learn more about those values and declare variable types. Then, we start pointing to where that value is stored in the computer’s memory. Finally, we load values from specific memory locations into registers.

You, too, can write low level, high-performing code. Just take it baby step by baby step.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store