Machine Code
In the real world, the processing components of our computers are made up of gates which control the flow of electrical current. Just like we abstracted electrical current into the idea of data, we can abstract electrical current into the idea of instructions. For this we again use binary values (0 or 1) and group them together. A group represents a single instruction to the computer, and all of the instructions together are called machine code. Each machine code instruction tells the computer to complete a basic computation - adding, subtracting, multiplying, dividing, comparing, or moving values. These very simple actions are performed very quickly, and can be used to create everything you have ever seen a computer do. However, most programs are not written using just these instructions - we need to use abstraction again to see how we can make more meaningful things.
Let’s explore the application of abstraction to the instructions we give computers. This will set the foundation for all of the programming you will learn.
Programming in Machine Code
The following snippet shows a chunk of the machine code for a small program. You can see that 1s and 0s are grouped together. These groups form the instructions that are followed by the computer when this program is executed. Programs can be written directly in machine code like this, but it is a time consuming task. The task is further complicated by the fact that machine code is unique to each kind of CPU. For example, instructions for CPUs using the x86 architecture differ from instructions for CPUs using the ARM architecture. This means that programming at this level is entirely dependent on the kind of processor that you are targeting.
It is extremely difficult to work at this level of detail, and fortunately you don’t need to. Software developers have created tools to help us to work at higher levels of abstraction and create programs without having to think about low level details. These tools work by taking the code you write and doing the tedious work of converting that code into the machine code of the computer you want to run it on.