Nepedia
Back to Discover
Fluent Reader
💻

Machine code

technology Maturity 11-13 Next article →

Machine code is the most basic way to talk to a computer. It is a special way of arranging data to control the central processing unit, or CPU. You can think of the CPU as the brain of the computer. Every computer program is mostly made of long sequences of these machine-code instructions. Because the CPU reads this code directly, it is called native language. This language allows the hardware to know exactly what to do at any moment.

Machine language and assembly language
Machine language and assembly language

How does this code actually work? Each instruction tells the CPU to perform a specific task. For example, it might tell the CPU to load a word from memory into a register. It could also tell the CPU to perform math using an arithmetic logic unit, which is often called an ALU. Some instructions tell the CPU to jump or skip to a different instruction. This allows the computer to follow different paths through a program. The instructions are made of patterns of bits that trigger the computer's digital circuits.

W65C816S Machine Code Monitor
W65C816S Machine Code Monitor

Writing machine code by hand is a very hard job. It is tedious and it is easy to make mistakes. To make it easier, people use assembly language. Assembly language uses short words, called mnemonics, to represent the numbers in machine code. For instance, the word NOP in assembly for an x86 processor represents the code 0x90. Most people today use high-level programming languages instead of assembly. These languages are much easier for humans to read and write.

Machine language and assembly language
Machine language and assembly language

Different types of computers use different instruction sets. This is called an instruction set architecture, or ISA. An ISA defines how a CPU works and varies by its design family. For example, x86 and ARM are two different families. Usually, code for one family will not work on the other. However, some special designs can handle more than one. The VAX architecture can support the PDP-11 set. The PowerPC 615 can process both PowerPC and x86 instructions natively.

W65C816S Machine Code Monitor
W65C816S Machine Code Monitor

Machine code is very different from the code humans write. The writer Douglas Hofstadter compared looking at machine code to examining the atoms of a DNA molecule. Since it is hard to read, we use special tools to understand it. A tool called a disassembler can turn machine code back into assembly language. A decompiler can try to turn it into a high-level language. Programmers also use debuggers to interact with the code while they fix problems. This helps them see how the computer is behaving in real time.

419 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (2)
File:W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg
File:Machine language and assembly language.jpg
Machine language and assembly language.jpg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.