programacion-codigo-maquina

What is Machine Code

  • 5 min

Machine code is a VERY low-level programming language that is directly executable by the central processing unit (CPU) of a computer.

If we open an executable program, we will see a jumble of data like the following (but with many, many, many! more lines)

00 F3 0F 6F 05 D7 8E 06 00 0F 11 74 24 60 0F 11 44 24 70 41 80 FD 03 0F 84
9B 03 00 00 8B 7E 04 45 31 F6 85 FF 0F 89 AF FD FF FF 80 7E 08 00 0F 84 DB
02 00 00 31 FF 41 80 FD 01 40 0F 94 C7 83 C7 06 E9 AD FD FF FF 66 0F 1F 84 
00 00 00 00 00 80 7C 24 6F 01 0F 84 3D 04 00 00 8B 44 24 60 48 83 F8 03 0F 
86 5A 02 00 00 BA 03 00 00 00 E9 0E FF FF FF 0F 1F 44 00 00 40 84 ED 48 8D 
3D 43 84 06 00 48 8D 05 40 84 06 00 48 0F 45 F8 E9 C8 FE FF FF 66 0F 1F 44 
00 00 45 84 F6 0F 84 17 03 00 00 45 0F B6 F6 48 8D 05 BC 83 06 00 48 C7 44 
24 70 01 00 00 00 41 BD 01 00 00 00 42 0F B6 04 30 88 84 24 80 00 00 00 48 
8D 44 24 50 48 89 44 24 30 66 0F EF F6 C6 44 24 50 25 44 8B 76 04 48 8D 54 
24 51 F3 0F 5A F1 40 84 FF 74 0A C6 44 24 51 23 48 8D 54 24 52 45 85 F6 78
0F 0F B7 05 12 8E 06 00 48 83 C2 02 66 89 42 FE 40 80 FD 01 C6 42 01 00 BF 
F4 01 00 00 4C 89 FB 19 C0 83 E0 20 83 C0 41 88 02 49 8D 45 01 48 89 44 24 
38 0F 1F 00 4C 29 EF 4A 8D 0C 2B 48 89 FD 45 85 F6 0F 88 A4 00 00 00 4C 8B 
44 24 30 F2 0F 11 74 24 20 45 89 F1 48 89 FA E8 17 F4 FE FF 48 8B 7C 24 78 
48 8B 5C 24 68 85 C0 0F 88 A4 00 00 00 48 98 48 39 E8 0F 82 EA 00 00 00 48 
8B 54 24 38 48 01 D0 48 39 C7 73 AD 48 89 FD 48 D1 ED 48 01 FD 48 39 C5 48

(... many, many, many more lines)
Copied!
Example of machine code

What is that? That is machine code, meaning the binary code necessary for your processor to execute the program. This is the only language your processor understands.

Each instruction corresponds to a specific basic operation that the CPU can execute. They are very basic and simple operations (for example, adding two numbers, transferring data from one place to another in memory, or comparing two numbers).

The available instructions vary between architectures and processor models. An old x86 8088 had about 81 instructions. A modern processor can have several hundred instructions available.

Machine code uses these elementary instructions by calling them by their “operation code” (opcode, which is simply a numerical representation we give to each instruction).

opcodes

Instruction stack

As we can see, machine code is completely dependent on the underlying hardware. Each processor has its own instruction set, its own opcodes, and its own register structure.

This means that machine code written for a specific processor architecture is not directly compatible with a different processor. That bunch of bytes will only work on a processor of a specific type.

Another evident characteristic of machine code is that its readability for humans is very low. It consists of a sequence of zeros and ones, making it very difficult for humans to understand and maintain. Furthermore, machine code lacks the abstractions and advanced control structures found in high-level programming languages.

Believe it or not, in the early days of programming, people programmed like this. And as you can imagine, programming in that was a nightmare. It was a very slow, complicated, and error-prone process. That’s why other languages soon emerged, like Assembly, which made the process easier.

Although machine code is considered (and is) a low-level programming language, its direct use in modern application development is very limited (if not practically non-existent).

Today, most programmers use high-level programming languages, such as C++ or Python, which offer abstractions and control structures more friendly for software development.