See all glossary termsIn computer programming, instructions are a single operation the computer recognizes and can execute.
For example, a function call, an addition, or assigning a value to a variable.
var value := 10 + 15
Any code we write is an instruction. It tells the computer what to do.
Calling it "instruction" is not a coincidence: it's because code is just text; it doesn't do anything. When typing code in a modern interface, it's easy to get fooled and think the code is the program, because of all the fancy colors and the error messages and the autocomplete. But it's just dead text.
What makes it alive is the computer, which reads the text, interprets it, and executes the instructions if it can. It might also decide to skip certain instructions if they're not needed, or optimize others, depending on how it was programmed.
At the lowest level, instructions are binary operations that the CPU can execute. These are called "operation code" instructions, also called opcodes.
Opcodes operate on data, which is stored in memory or registers. The CPU fetches the data, performs the operation, and stores the result back in memory or a register (a register a is very fast memory unit located on the chip).
For example, in a hypothetical assembly language, an instruction to add two numbers might look like this:
ADD R1, R2, R3
Here the opcode ADD
takes the values stored in registers R2
and R3
, adds them together, and stores the result in register R1
.
Because writing Assembly can be somewhat unyieldy, low level compiled languages like C or Rust give us an easier way to write instructions, by abstracting the opcodes into keywords and functions, which get compiled to Assembly. Higher level interpreted languages like Python or GDScript abstract it in a different way: they have a pre-compiled program that can run the opCodes, and reads the instructions from a file.
Assembly itself is an abstraction over the raw binary instructions, giving human-readable names to the opcodes and registers. This makes it easier to write and understand, but it's still very close to the machine code that the CPU executes.
Those binary codes operate on the actual hardware of the CPU. Anything a computer does boils down to enormous amounts of extremely simple operations like adding two numbers, comparing two values, or moving data around, that could be done by a human. Computers just do it very, very fast.
See Also
Related terms in the Glossary
External Links
Handpicked resources on the internet
school.gdquest.com - 0.3.5-2024-11-14T22:16:40.217Z-