Assembler and the Beginning of Low-Level Programming. Part 1.

//Assembler and the Beginning of Low-Level Programming. Part 1.

I’ve always been interested in how things work under the hood. Unfortunately, computer science courses I’ve taken in the university haven’t covered low-level details of how a computer works. And the last Uncle Bob’s blog post “Make the Magic go away” convinced me that it’s time to play a little bit at a low level. At first I was thinking about reading a book on IL written by Serge Lidin (as far as I’m a C#-programmer), but then I decided to take a look at the lowest level a programmer can dive into – Assembler. So I made a couple of queries on amazon and found an interesting book named “Assembly Language Step-by-Step: Programming with Linux” by Jeff Duntemann. This book has a pretty high rating and good reviews.

Now, I’m on 117-th page and… there hasn’t been any assembler practice yet… surprise 🙂 Actually, this is not so surprising as I thought at first. The primary audience of this book are newcomers to the low-level world. In case you are a newbie in this field, it would be quite silly to start learning assembler beginning with processor instructions. As the author says, “Nearly all books on assembly start by introducing the concept of an instruction set, and then begin describing machine instructions, one by one. This is moronic, and the authors of such books should be hung. Even if you’ve learned every single instruction in an instruction set, you haven’t learned assembly language.” The thing is that the most important part of working within the low level is memory addressing. The author says about this, “Any idiot can learn machine instructions. Many do. The skill of assembly language consists of a deep comprehension of memory addressing. Everything else is details – and easy details at that.”

There are two essential parts in learning memory addressing:

  • Understanding how to convert values between binary and hexadecimal representations. Moreover, you have to learn how to do it fast using your own brain, not a calculator.
  • Understanding of some details about how the PC’s hardware work: what is data bus, addressing lines, memory models and some other things.

It seems we can’t calculate in hex and binary as fast as we can in decimals. Hex and binary are just not so convenient. We can’t achieve the same speed of calculating not because we are just not accustomed to calc in hex and binary, but because those systems are really harder to calculate in. That’s it, we can’t do much about that. Of course, there is something we can do to speed up a little our abilities to calculate in hex and binary.

Converting between hex and binary is simple, indeed. We can divide a binary value into 4-bit parts (referred as nibbles, half-bytes, etc) and then convert them into hex-values independently, which is a simple task after some practice. Hex into bin can be converted the same way, only vice-versa. So, binary and hex bases are like siblings, they are quite close to each other, hex is just more convenient for people, because hex-values are much shorter. For example, lets convert 1101111110010010 into hex.

1101 1111 1001 0010

D      F       9       2

Quite simple. For addition we have to memorize the following table:

hex with decimals sums tableThis is the first part of a long journey in the low-level world. I think, I’ll write about the whole bunch of stuff, such as memory models, stacks, heaps, main parts of an operating system (such as Linux) and much more.

By |2016-04-27T11:16:12+00:00August 29th, 2015|Fundamentals|0 Comments

About the Author:

I'm thankful enough for that I love what I do. I began my career as a postgraduate student participating in Microsoft ImagineCup contest. I've been working with .NET platform since 2003. I've been professionally architecting and implementing software for nearly 7 years, primarily based on .NET platform. I'm passionate about building rich and powerful applications using modern technologies. I'm a certified specialist in Windows Applications and Service Communication Applications by Microsoft. "If it's work, we try to do less. If it's art, we try to do more." - Seth Godin. What I can say is that software is my art.