seegongsik
Structure

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.

01

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."

Add
#3 + #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.

02

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.

What (Add)
0010
Where (#3)
0011
Where (#7)
0111

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.

03

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.

Fetch
Take a value out of some memory cell
Store
Put a value into some memory cell
Add
Add two values (the adder from lesson 6 works)
Jump
Jump to another set instruction

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.

04

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.

0010 0011 0111
What
Add
Where
#3
Where
#7

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.

05

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.

1Fetch #5Fetch value (10) in #5
2Fetch #6Fetch value (7) in #6
3Add, store in #710 + 7 = 17
#5
10
#6
7
#7
0
Press run to go line by line

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.

In one lineAn instruction is "what and where" written in 0s and 1s, the smallest unit of language a machine understands. String together a handful of basic instructions, and that's a program.
← Structure
Was this helpful? Support seegongsik