What is a machine instruction
So far we've covered circuits that calculate, circuits that remember, and addresses. So how do you tell these parts "do this"? It's time to meet the language a computer understands: instructions.
An instruction is "what" plus "where"
The orders you give a computer are very simple.
Two parts are all it takes: "what to do" and "where" or "on what."
For example: "Add: cells 3 and 7."
What (add) + where (cells 3 and 7).
In everyday words, that's "add cell 3 and cell 7."
Short and clear.
A computer takes these little orders one at a time and carries them out, and each one is called an instruction.
Instructions are written in 0s and 1s too
But a computer knows neither Korean nor English, only 0s and 1s.
So instructions are written in 0s and 1s as well.
The front part says what to do and the back part says where, each in a fixed position with a fixed pattern.
The first 4 bits are the kind of instruction; the rest is the target address.
To us it's just a row of 0s and 1s, but to the computer it's a perfect sentence: "Add cells 3 and 7."
Look at the fixed positions and the meaning reads clearly.
It knows only a handful of words
Here's a surprising fact: a computer knows fewer instructions than you'd think.
Fetch a value, store a value, add, jump somewhere else: just a few basic instructions like these.
With this tiny vocabulary, it does everything.
Wire these simple instructions together countless times, and you get games and videos.
A small vocabulary is fine.
Just as short words can tell a long story, these few instructions, combined millions of times, can do almost anything.
How the computer reads an instruction
So how does a computer read these 0s and 1s?
It cuts them at the fixed positions.
It sees the front part and knows "this means add," then sees the back part and knows "cells 3 and 7."
Reading an instruction by splitting it up like this is called decoding.
Press the decode button below and the meaning of each part appears.
Cut at the fixed positions and read off the meaning.
Fixed positions, fixed meanings.
That's why a computer can tell exactly what to do and where, just from 0s and 1s.
It works because there's an agreement.
String instructions together and you have a program
One instruction is small, but string them together and they get something done.
"Fetch the value at 5, fetch the value at 6, add them and store the result at 7": those three lines make an addition program.
Press run and it steps through one line at a time.
A three-line mini program.
What you just saw is the very bottom layer of how a computer works.
Every program we use is, in the end, made of millions of instructions like these.
In the next lesson, we'll find out where subtraction and comparison happen, not just addition.