Log in Sign up
Back to Discover
💻

Machine code

technology Maturity 11-13

Computers use a special way to talk.

Machine language and assembly language.jpg
Machine language and assembly language.jpg
It is a set of rules. These rules tell the computer what to do. It helps the computer work fast. We use it to run programs. Can you see how it works?

44 words

Computers have a special way to work.

Machine language and assembly language.jpg
Machine language and assembly language.jpg
They use code to follow rules. This code tells the computer what to do. It can tell the computer to move data. It can also tell it to do math.
W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg
This code is hard for people to read. It is mostly just patterns of bits. A computer reads this code directly. This helps the computer run its programs. It is how a computer thinks!

80 words

Computers need instructions to work. They use a special type of data called machine code.

Machine language and assembly language.jpg
Machine language and assembly language.jpg
This code is the language a CPU uses directly. The CPU is the central processing unit. It is the part of the computer that follows instructions.

Machine code tells the CPU to do specific tasks. It can tell the CPU to move data from one place to another. It can also tell the CPU to do math. Some instructions tell the CPU to jump to a new task.

W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg
Writing in machine code is very hard for people. It is mostly made of patterns of bits. Instead, people often use assembly language. Assembly language uses short words to represent the numbers in machine code.

Different families of computers use different sets of instructions. This is called an instruction set architecture, or ISA. An ISA tells the CPU how to act. Because of this, code for one type of CPU might not work on another. Some special computers can run more than one type of code. Most machine code is stored in RAM while it is running.

189 words

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.jpg
Machine language and assembly language.jpg

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.jpeg
W65C816S Machine Code Monitor.jpeg

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.jpg
Machine language and assembly language.jpg

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.jpeg
W65C816S Machine Code Monitor.jpeg

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.

432 words

Machine code is the fundamental data structure used to control a computer's central processing unit (CPU). It consists of encoded sequences that the CPU interprets directly through its programmable interface. Because the CPU reads this language without needing a translator, machine code is considered native to its host processor. Most computer programs are primarily composed of these machine-code instructions. Without this low-level language, the hardware would have no way to execute the tasks required by software.

Machine language and assembly language.jpg
Machine language and assembly language.jpg

Each machine instruction is a specific pattern of bits that triggers the computer's digital logic. These instructions act on various hardware components to perform precise tasks. For example, an instruction might load a word from memory into a CPU register. It might also command the arithmetic logic unit (ALU) to perform a calculation on specific data. Other instructions allow the CPU to jump or skip to a different instruction in the sequence. This process allows the processor to control registers, the bus, and memory to execute complex programs.

Instruction sets are organized into different formats and types. Instructions can be general-purpose or special-purpose. General-purpose instructions handle common tasks like data movement, comparisons, and loop control. Special-purpose instructions exploit unique features found only in a specific computer architecture. Furthermore, instructions may vary in length. Some sets use instructions that are all the same size, while others use variable lengths. Designers must also decide how many bits to allocate to the address field. A shorter address field can increase execution speed, but it might limit the amount of physical memory the CPU can access.

To make programming easier, humans often use assembly language instead of writing raw machine code. Assembly language provides a direct mapping to machine code by using mnemonics and labels. For instance, in an x86 processor, the assembly mnemonic NOP represents the opcode 0x90. While possible, writing programs directly in machine code is considered tedious and error-prone. Most modern software is instead written in high-level programming languages. These languages are then translated down into the machine code that the hardware understands.

Machine language and assembly language.jpg
Machine language and assembly language.jpg

An instruction set architecture (ISA) defines the specific interface for a CPU. Different families of CPU design, such as x86 or ARM, use different ISAs. Generally, machine code designed for one family will not work on another. However, some architectures provide optional support for other instruction sets. The VAX architecture can support the PDP-11 set, and the IA-64 architecture can support the IA-32 set. The PowerPC 615 is another example, as it can natively process both PowerPC and x86 instructions.

W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg

In certain systems, an even deeper layer called microcode exists. Microcode provides a common machine language interface across different models of a computer family. This helps developers port machine language programs between models with different dataflows. The IBM System/360 family is a notable example of this approach. Additionally, some architectures use a technique called overlapping instructions. In the 1970s and 1980s, this was used to save memory space. Today, it is rarely used except for extreme optimization, such as in boot loaders, or for code obfuscation to prevent tampering.

W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg

Understanding machine code is difficult because it is not human-readable. The writer Douglas Hofstadter compared examining machine code to looking at the atoms of a DNA molecule. To help programmers, several specialized tools are used. A disassembler decodes machine code back into assembly language. A decompiler attempts to convert it into a high-level language, though the result can be hard to read. Debuggers allow programmers to interact with the code to find and fix errors. These tools often use debug symbols to map the machine code back to the original source code.

W65C816S Machine Code Monitor.jpeg
W65C816S Machine Code Monitor.jpeg

621 words
🖼️ 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
Up Next
💻
Low-level programming language
Technology
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.