Chapterبەش 2 · Lectureوانە 2.6
How a Computer Runs a Programکۆمپیوتەر چۆن بەرنامەیەک جێبەجێ دەکات
Follow the owner's program through a tiny computer: instructions and data in RAM, the registers PC, MAR, MDR, IR and R1–R3, the ALU and the three buses. Then name the steps — the fetch–decode–execute cycle — and see how a line of code becomes machine instructions.
بە ناو بچووکدا بگرەوە: و لە ، PC، MAR، MDR، IR و R1 تا R3، و سێ . پاشان ناوی هەنگاوەکان — — دەناسیت و دەبینیت چۆن دێڕێک کۆد دەبێت بە ئامێر.
What you will learnچی فێر دەبیت
- Explain that a program is a list of instructions held in RAM, and how it gets there.
- Name the parts that run a program: control unit, ALU, registers, RAM and buses.
- Trace LOAD, add and STORE instructions step by step and write a trace table.
- Describe the fetch–decode–execute (–store) cycle and the jobs of the PC and the IR.
- Correct two common myths: «STORE runs the program» and «users type instructions into RAM».
- ڕوونی بکەیتەوە کە لیستێکی لە و چۆن دەگاتە ئەوێ.
- ئەو بەشانە ناو ببەیت کە جێبەجێ دەکەن: ، ، ، و .
- LOAD، کۆکردنەوە و STORE هەنگاو بە هەنگاو بگریتەوە و بنووسیت.
- (هێنان، شیکردنەوە، جێبەجێکردن، هەڵگرتن) و کاری PC و IR وەسف بکەیت.
- دوو بیروڕای هەڵەی باو ڕاست بکەیتەوە: «STORE کارا دەکات» و « دەنووسێتە ناو ».
A program is a list of instructionsبەرنامە تەنها لیستێکی ڕێکارنامەیە
Every app you use — a calculator, a game, a chat app — is a program. A program is only a list of instructions: small, exact steps that the computer carries out one after another. People write programs in a programming language, and a programming language is itself built from a set of instructions.
هەر کە بەکاری دەهێنیت — ، یاری یان چات — . تەنها لیستێکی ، واتە هەنگاوی بچووک و ورد کە یەک لە دوای یەک جێبەجێیان دەکات. مرۆڤ بە دەنووسێت؛ خۆیشی لە کۆمەڵێک پێکهاتووە.
This lesson opens the box and follows one tiny program, step by step, as it runs inside the CPU and RAM. The idea is the same in every computer and every programming language.
ئەم وانەیە سندووقەکە دەکاتەوە و زۆر بچووک هەنگاو بە هەنگاو دەگرێتەوە، لە کاتێکدا لەناو و جێبەجێ دەبێت. ئەم بیرۆکەیە لە هەموو و هەموو هەمان شتە.
A recipe for dolma is a list of steps: wash the vine leaves, fill them, roll them, cook them. You follow the lines in order, one at a time. A computer follows a program in the same way.
ڕێچکەی دۆڵمە لیستێکی هەنگاوە: گەڵا مێوەکان بشۆ، پڕیان بکە، بیانپێچە، لێیان بنێ. هێڵەکان بە ڕیز، یەک لە دوای یەک، جێبەجێ دەکەیت. بە هەمان شێوە جێبەجێ دەکات.
Where the analogy stops workingسنووری ئەم نموونەیە
A cook understands the recipe and can fix a mistake in it. The CPU understands nothing: it carries out each instruction exactly as written, even a wrong one, and it does billions of them every second.
چێشتلێنەر لە ڕێچکەکە تێدەگات و دەتوانێت هەڵەیەکی تێدا چاک بکاتەوە. لە هیچ تێناگات: هەر وەک خۆی جێبەجێ دەکات، تەنانەت ئەگەر هەڵەش بێت. هەروەها لە هەر چرکەیەکدا ملیارەها جێبەجێ دەکات.
A program is a list of instructionsبەرنامە تەنها لیستێکی ڕێکارنامەیە
Example: which number is larger?نموونە: کام ژمارە گەورەترە؟
Here is a small program written as plain steps (pseudocode). It reads two numbers and shows the larger one.
ئەمە بچووکە کە بە هەنگاوی سادە نووسراوە (). دوو ژمارە وەردەگرێت و گەورەترەکەیان پیشان دەدات.
1. Input number1
2. Input number2
3. Compare the two numbers
4. If number1 > number2, output number1
5. Otherwise, output number2Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
Two input steps: the user types two numbers.
دوو هەنگاوی : دوو ژمارە دەنووسێت.
- Lineدێڕی 3-5
One comparison and two possible outputs.
یەک بەراوردکردن و دوو گونجاو.
The course slide also shows the same steps in the C language. Here they are with the slide's mistakes fixed. You do not need to learn C here: notice only that every line is still one small instruction.
سلایدی وانەکە هەمان هەنگاوەکانی بە زمانی C نووسیوە. لێرەدا هەڵەکانی سلایدەکە چاک کراون. پێویست ناکات لێرەدا C فێر ببیت: تەنها تێبینی بکە کە هەر دێڕێک هێشتا بچووکە.
#include <stdio.h>
int main(void) {
int number1, number2;
scanf("%d", &number1);
scanf("%d", &number2);
if (number1 > number2)
printf("%d is greater\n", number1);
else
printf("%d is greater\n", number2);
return 0;
}input: 7 3 → 7 is greater input: 2 9 → 9 is greater input: 5 5 → 5 is greater
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
The two numbers must be declared before they are used.
دەبێت دوو ژمارەکە پێش بەکارهێنان ڕابگەیەنرێن.
- Lineدێڕی 5-6
Input: read two whole numbers.
: دوو وەردەگرێت.
- Lineدێڕی 7-10
Compare, then output the larger one.
بەراورد دەکات، پاشان گەورەترەکە دەردەخات.
A tiny computer to watchکۆمپیوتەرێکی بچووک بۆ سەیرکردن
To watch a program run, we use a tiny model computer. It comes from an instructional video (eChalk, «How does a computer run a program?») that the course paper on this topic explains; here it is redrawn. It has only the parts that matter:
بۆ ئەوەی ببینین چۆن جێبەجێ دەبێت، نموونەیی بچووک بەکار دەهێنین. ئەم نموونەیە لە ڤیدیۆیەکی فێرکارییەوە هاتووە (eChalk، «How does a computer run a program?») کە نووسراوی وانەکە لەسەر ئەم بابەتە ڕوونی دەکاتەوە؛ لێرەدا دووبارە کێشراوەتەوە. تەنها ئەو بەشانەی تێدایە کە گرنگن:
- CPU — the control unit reads each instruction and directs the other parts; the ALU does the calculations; the registers hold the numbers it is working on right now.
- RAM — holds the program's instructions and its data (RAM: the working memory).
- Buses — the wires between them: the address bus says where, the data bus carries what, the control bus says read or write.
- — یەکەی جڵەوکردن هەر دەخوێنێتەوە و بەشەکانی تر ئاراستە دەکات؛ یەکەی ژیربێژیی بیرکارییانە حیسابەکان دەکات؛ ئەو ژمارانە هەڵدەگرن کە ئێستا کاریان لەسەر دەکرێت.
- — و هەڵدەگرێت (RAM: بیرگەی کار).
- — ئەو تەلانەی نێوانیان: دەڵێت لە کوێ، چی دەگوازێتەوە، دەڵێت بخوێنەوە یان بنووسە.
Picture a shopkeeper in the bazaar doing the day's accounts. His big ledger, with numbered lines, is RAM. The two or three numbers he writes on a small card on the counter are the registers. His calculator is the ALU. He himself, reading the job list line by line and deciding what to do, is the control unit.
دووکاندارێک لە بازاڕدا بهێنە بەرچاوت کە حیسابی ڕۆژەکە دەکات. دەفتەرە گەورەکەی، کە دێڕەکانی ژمارەیان هەیە، . ئەو دوو سێ ژمارەیەی لەسەر کارتێکی بچووک لەسەر مێزەکە دەینووسێت . . خۆی، کە لیستی کارەکان دێڕ بە دێڕ دەخوێنێتەوە و بڕیار دەدات چی بکات، .
Where the analogy stops workingسنووری ئەم نموونەیە
The shopkeeper thinks; the CPU only follows instructions, billions of times a second. And unlike a paper ledger, ordinary RAM forgets everything when the power goes off.
دووکاندار بیر دەکاتەوە؛ تەنها جێبەجێ دەکات، ملیارەها جار لە چرکەیەکدا. هەروەها بە پێچەوانەی دەفتەری کاغەز، ئاسایی کاتێک کارەبا دەبڕێت هەموو شتێک لەبیر دەکات.
A tiny computer to watchکۆمپیوتەرێکی بچووک بۆ سەیرکردن
RAM: numbered places for instructions and dataRAM: شوێنی ژمارەدار بۆ ڕێکارنامەکان و دراوە
RAM is a long row of storage places. Each place has a number, its memory address, just as each house in a street has a house number. The CPU finds a value by its address.
ڕیزێکی درێژی شوێنی هەڵگرتنە. هەر شوێنێک ژمارەیەکی هەیە کە پێی دەوترێت ، وەک چۆن هەر خانوویەک لە شەقامێکدا ژمارەیەکی هەیە. بەهایەک لە ڕێگەی ناونیشانەکەیەوە دەدۆزێتەوە.
In our model RAM has two parts. The Data part has places named A1, A2, A3, A4, A5 … for storing data. The Instructions part holds the orders that tell the computer what to do with that data.
لە نموونەکەماندا دوو بەشی هەیە. بەشی شوێنی بە ناوی A1، A2، A3، A4، A5 … ی هەیە بۆ هەڵگرتنی . بەشی هەڵدەگرێت کە بە دەڵێن چی لەو بکات.
A tiny computer to watchکۆمپیوتەرێکی بچووک بۆ سەیرکردن
Who puts the instructions into RAM?کێ ڕێکارنامەکان دەخاتە ناو RAM؟
A tiny computer to watchکۆمپیوتەرێکی بچووک بۆ سەیرکردن
Registers and the ALUتۆمارگەکان و یەکەی ژیربێژیی بیرکارییانە
Registers are a few tiny, very fast cells inside the CPU. They hold the data the CPU is working on at this moment. Our model has three general-purpose registers, R1, R2 and R3, plus four special registers (PC, MAR, MDR and IR) that you will meet in a moment.
چەند خانەیەکی زۆر بچووک و زۆر خێران لەناو . ئەو هەڵدەگرن کە لەم ساتەدا کاری لەسەر دەکات. نموونەکەمان سێ هەیە، R1، R2 و R3، لەگەڵ چوار تایبەت (PC، MAR، MDR و IR) کە کەمێکی تر دەیانناسیت.
The ALU (arithmetic logic unit), also inside the CPU, does the work on that data: arithmetic operations such as adding and subtracting, and logical operations such as comparing two numbers. It takes its numbers from registers and puts its answer in a register — never straight from RAM.
(ALU)، کە ئەویش لەناو ، کار لەسەر ئەو دەکات: وەک کۆکردنەوە و لێدەرکردن، هەروەها وەک بەراوردکردنی دوو ژمارە. ژمارەکانی لە وەردەگرێت و وەڵامەکەی دەخاتە — هەرگیز ڕاستەوخۆ لە نا.
So RAM is outside the CPU and the registers are inside it. The full list of registers and what each one does is in Registers and buses.
کەواتە لە دەرەوەی و لە ناوەوەیدان. لیستی تەواوی و کاری هەریەکەیان لە تۆمارگەکان و تێپەڕگەکان دایە.
The instruction set: the CPU's vocabularyکۆمەڵە ڕێکارنامە: وشەکانی CPU
A CPU understands only a fixed list of instructions, called its instruction set. Our model knows four. LOAD and STORE move numbers between RAM and the registers; the other two use the ALU.
تەنها لە لیستێکی دیاریکراوی تێدەگات کە پێی دەوترێت . نموونەکەمان چوار دەزانێت. LOAD و STORE ژمارە لە نێوان و دەگوازنەوە؛ دووەکەی تر بەکار دەهێنن.
| Instruction | What it doesچی دەکات | Exampleنموونە |
|---|---|---|
LOAD address → register | Copies a value from a RAM address into a register.بەهایەک لە ناونیشانێکی کۆپی دەکات بۆ ناو . | LOAD A1 → R1 |
STORE register → address | Copies a value from a register into a RAM address.بەهایەک لە کۆپی دەکات بۆ ناو ناونیشانێکی . | STORE R3 → A3 |
R1 + R2 → R3 | The ALU adds R1 and R2 and puts the result in R3. R1 و R2 کۆ دەکاتەوە و ئەنجامەکە دەخاتە ناو R3. | 5 + 2 → 7 |
R1 − R2 → R3 | The ALU subtracts R2 from R1 and puts the result in R3. R2 لە R1 کەم دەکاتەوە و ئەنجامەکە دەخاتە ناو R3. | 5 − 2 → 3 |
The instruction set: the CPU's vocabularyکۆمەڵە ڕێکارنامە: وشەکانی CPU
Real instruction setsکۆمەڵە ڕێکارنامەی ڕاستەقینە
Real instruction sets are much bigger: hundreds of instructions for adding, comparing, jumping to another instruction and more. The big families today are x86-64 (Intel and AMD) and Arm (phones, Apple's Macs and many new laptops) — see Who makes processors in 2026. A program built for one family does not run directly on the other (x86 or Arm).
لە ڕاستەقینەدا زۆر گەورەترە: سەدان بۆ کۆکردنەوە، بەراوردکردن، بازدان بۆ تر و زیاتر. ئەمڕۆ دوو خێزانی گەورە هەن: x86-64 (Intel و AMD) و Arm (مۆبایل، Macـەکانی Apple و زۆرێک لە لاپتۆپە نوێیەکان). بڕوانە کێ لە 2026ـدا پرۆسێسەر دروست دەکات. کە بۆ خێزانێک دروست کرابێت ڕاستەوخۆ لەسەر خێزانەکەی تر کار ناکات (x86 یان Arm).
Planning پلاندانان بۆ
Our job: add the number in A1 (5) to the number in A2 (2) and keep the answer in A3. First write the plan. The course paper calls this plan sheet the «Target RAM»: what each address should hold when we finish.
ئەرکەکەمان: ژمارەی ناو A1 (5) و ژمارەی ناو A2 (2) کۆ بکەینەوە و وەڵامەکە لە A3ـدا هەڵبگرین. سەرەتا پلانەکە دەنووسین. نووسراوی وانەکە بەم پەڕەی پلانە دەڵێت «Target RAM»: واتە کاتێک تەواو دەبین هەر ناونیشانێک دەبێت چی هەڵبگرێت.
| Addressناونیشان | Nowئێستا | When finishedدوای تەواوبوون |
|---|---|---|
A1 | 5 | 5 |
A2 | 2 | 2 |
A3 | emptyبەتاڵ | 7 |
- Load the first numberژمارەی یەکەم بهێنە
Choose the RAM address that is our starting point, A1, and one of the three registers, R1:
LOAD A1 → R1. When this instruction runs, the 5 in A1 goes straight into R1 in the CPU.ناونیشانێکی هەڵبژێرە کە خاڵی دەستپێکمانە (A1)، لەگەڵ یەکێک لە سێ ، واتە R1:
LOAD A1 → R1. کاتێک ئەم جێبەجێ دەبێت، ژمارە 5ـی ناو A1 ڕاستەوخۆ دەچێتە ناو R1 لە . - Load the second numberژمارەی دووەم بهێنە
Do the same for A2 and R2:
LOAD A2 → R2. Now R2 holds 2.هەمان کار بۆ A2 و R2 بکە:
LOAD A2 → R2. ئێستا R2 ژمارە 2 هەڵدەگرێت. - Addکۆی بکەرەوە
R1 + R2 → R3makes the ALU add what is in R1 and R2 and put the result, 7, in R3.R1 + R2 → R3وا دەکات ناوەڕۆکی R1 و R2 کۆ بکاتەوە و ئەنجامەکە، واتە 7، بخاتە ناو R3. - Store the answerوەڵامەکە هەڵبگرە
STORE R3 → A3keeps the contents of R3 in a data cell of RAM. We choose A3 because A1 and A2 already hold 5 and 2, which we may still need.STORE R3 → A3ناوەڕۆکی R3 لە خانەیەکی هەڵدەگرێت. A3 هەڵدەبژێرین چونکە A1 و A2 خۆیان 5 و 2 هەڵدەگرن و لەوانەیە هێشتا پێویستمان پێیان بێت.
Planning پلاندانان بۆ
The whole program in RAMهەموو بەرنامەکە لە RAMـدا
Put together, the four steps are four instructions, stored one after another in the Instructions part of RAM, at addresses 0 to 3:
کاتێک پێکەوە دادەنرێن، چوار هەنگاوەکە دەبنە چوار کە یەک لە دوای یەک لە بەشی هەڵگیراون، لە ناونیشانی 0 تا 3:
0: LOAD A1 → R1
1: LOAD A2 → R2
2: R1 + R2 → R3
3: STORE R3 → A3Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1-2
Copy the two numbers from RAM into registers.
دوو ژمارەکە لە کۆپی دەکات بۆ ناو .
- Lineدێڕی 3
The ALU adds them inside the CPU.
لەناو کۆیان دەکاتەوە.
- Lineدێڕی 4
Copy the answer back into RAM.
وەڵامەکە دەگەڕێنێتەوە بۆ ناو .
Watch the program runسەیری جێبەجێبوونی بەرنامەکە بکە
Now press play. For every instruction the CPU does the same two things: first it fetches the instruction from RAM into the CPU, then it decodes and executes it. Watch the PC: it always holds the address of the next instruction.
ئێستا دەستی پێ بکە. بۆ هەر هەمان دوو کار دەکات: سەرەتا لە دەهێنێت بۆ ناو ، پاشان شیی دەکاتەوە و جێبەجێی دەکات. سەیری PC بکە: هەمیشە ناونیشانی دواتر هەڵدەگرێت.


LOAD A1 → R1— fetched from address 0; executing it reads A1 and puts 5 in R1.LOAD A2 → R2— fetched from address 1; puts 2 in R2.R1 + R2 → R3— fetched from address 2; the ALU adds,R3 = 7. No bus is needed: everything is inside the CPU.STORE R3 → A3— fetched from address 3; writes 7 into A3.
LOAD A1 → R1— لە ناونیشانی 0ـەوە دەهێنرێت؛ جێبەجێکردنی ئەم A1 دەخوێنێتەوە و 5 دەخاتە R1.LOAD A2 → R2— لە ناونیشانی 1ـەوە دەهێنرێت؛ 2 دەخاتە R2.R1 + R2 → R3— لە ناونیشانی 2ـەوە دەهێنرێت؛ کۆ دەکاتەوە و R3 دەبێتە 7. هیچ پێویست نییە: هەموو شتێک لەناو .STORE R3 → A3— لە ناونیشانی 3ـەوە دەهێنرێت؛ 7 لە A3ـدا دەنووسێت.
Watch the program runسەیری جێبەجێبوونی بەرنامەکە بکە
The run as a tableجێبەجێبوونەکە وەک خشتە
Programmers check a program with a trace table: after every instruction they write down what each register and memory place holds (trace tables in Fundamentals of Programming). Here is the trace table of our run.
بە دەپشکنن: دوای هەر دەنووسن کە هەر و هەر شوێنێکی چی هەڵدەگرێت (خشتەی بەدواداچوون لە بنەماکانی بەرنامەسازی). ئەمە بۆ جێبەجێبوونەکەمان.
| After instructionدوای | PC | IR | R1 | R2 | R3 | A3 |
|---|---|---|---|---|---|---|
| (start)(سەرەتا) | 0 | — | — | — | — | — |
| 0 | 1 | LOAD A1 → R1 | 5 | — | — | — |
| 1 | 2 | LOAD A2 → R2 | 5 | 2 | — | — |
| 2 | 3 | R1 + R2 → R3 | 5 | 2 | 7 | — |
| 3 | 4 | STORE R3 → A3 | 5 | 2 | 7 | 7 |
The fetch–decode–execute cycleسووڕی ڕێکارنامە: هێنان، شیکردنەوە و جێبەجێکردن
The steps the repeats for every : fetch it from memory (from the address in the ), decode it, execute it and store the result. Billions of these cycles happen every second.
ئەو هەنگاوانەیە کە بۆ هەر دووبارەیان دەکاتەوە: لە دەیهێنێت (لەو ناونیشانەی لە )، شیی دەکاتەوە، جێبەجێی دەکات و ئەنجامەکە هەڵدەگرێت. لە هەر چرکەیەکدا ملیارەها لەم سووڕانە ڕوو دەدەن.
The steps you watched have names. For every instruction, the processor repeats the same basic operations, called the machine cycle or instruction cycle:
ئەو هەنگاوانەی بینیت ناویان هەیە. پرۆسێسەر بۆ هەر هەمان هەنگاوە بنەڕەتییەکان دووبارە دەکاتەوە کە پێیان دەوترێت :
- Fetch — the control unit gets the next instruction (and the data it needs) from memory.
- Decode — the control unit works out what the instruction means and sets up the parts that will do it (with decoders).
- Execute — the ALU (or another part) carries it out.
- Store — the result is written into a register or into memory.
- هێنان — دواتر (و ئەو پێویستیەتی) لە دەهێنێت.
- شیکردنەوە — تێدەگات واتای چییە و ئەو بەشانە ئامادە دەکات کە جێبەجێی دەکەن (بە کۆدهەڵوەشێنەرەکان).
- جێبەجێکردن — (یان بەشێکی تر) ئەنجامی دەدات.
- هەڵگرتن — ئەنجامەکە لە یان لە دەنووسرێت.


A real processor repeats this cycle billions of times every second. A 3 GHz processor's clock ticks 3 billion times a second, and a modern core overlaps the steps of several instructions so that it can finish more than one per tick. How this speed is measured is in Processor speed, cache, GPUs and cooling.
پرۆسێسەرێکی ڕاستەقینە لە هەر چرکەیەکدا ملیارەها جار دووبارە دەکاتەوە. کاتژمێری پرۆسێسەرێکی 3 GHz لە چرکەیەکدا 3 ملیار جار لێ دەدات. هەروەها نوێ هەنگاوەکانی چەند تێکەڵ بە یەکتر دەکات بۆ ئەوەی لە هەر لێدانێکدا زیاتر لە یەک تەواو بکات. چۆنیەتیی پێوانی ئەم خێراییە لە خێرایی پرۆسێسەر، کاش، GPU و ساردکردنەوە دایە.
Fetch, decode, execute: the CPU uses a program counter, an instruction register and an accumulator to run instructions one by one.
، شیکردنەوە، جێبەجێکردن: بە ، و یەک لە دوای یەک جێبەجێ دەکات.
Watch 0:00-6:55. Stop before the sponsor message at 6:55.
لە 0:00 تا 6:55 سەیر بکە و پێش پەیامی سپۆنسەر لە 6:55 ڕابوەستە.
How the CPU knows what comes nextCPU چۆن دەزانێت دواتر چی دێت؟
The course paper never says how the CPU moves from one instruction to the next. Two special registers do it: the program counter (PC) holds the address of the next instruction, and the instruction register (IR) holds the instruction being carried out now. MAR and MDR are the CPU's «doorway» to RAM: MAR holds the address being used, MDR the value travelling in or out.
نووسراوی وانەکە هەرگیز نالێت چۆن لە دەچێتە سەر دواتر. دوو تایبەت ئەم کارە دەکەن: (PC) ناونیشانی دواتر هەڵدەگرێت. (IR) ئەو هەڵدەگرێت کە ئێستا جێبەجێ دەکرێت. MAR و MDR «دەرگای» بۆ : MAR ئەو ناونیشانە هەڵدەگرێت کە بەکار دێت؛ MDR ئەو بەهایەی کە دێتە ژوورەوە یان دەچێتە دەرەوە.
- Fetchهێنان
The address in the PC is copied into the MAR and sent on the address bus, with READ on the control bus.
ناونیشانی ناو PC کۆپی دەکرێت بۆ MAR و بە دەنێردرێت، لەگەڵ READ بە .
- Fetchهێنان
RAM sends the instruction back on the data bus into the MDR, and it is copied into the IR.
بە دەنێرێتەوە بۆ MDR. لەوێوە کۆپی دەکرێت بۆ IR.
- Fetchهێنان
The PC adds 1, so it already points to the next instruction.
PC یەک زیاد دەکات، بۆیە هەر ئێستا ئاماژە بە دواتر دەکات.
- Decodeشیکردنەوە
The control unit reads the IR and works out what to do.
IR دەخوێنێتەوە و دیاری دەکات چی بکرێت.
- Executeجێبەجێکردن
The parts named by the instruction do the work (a memory read or write, or an ALU operation). Then the cycle starts again with the new PC.
ئەو بەشانەی ناویان دەبات کارەکە دەکەن (خوێندنەوە یان نووسین لە ، یان حیسابێک لە ). پاشان بە PCـی نوێوە دەست پێ دەکاتەوە.
How the CPU knows what comes nextCPU چۆن دەزانێت دواتر چی دێت؟
Jumps: how ifs and loops workبازدان: ڕستەکانی if و خولەکان چۆن کار دەکەن
How JUMP and conditional jump instructions change the next address, so a list of instructions can make decisions and loops.
JUMP و بازدانی بە چۆن ناونیشانی داهاتوو دەگۆڕن، تا لیستێک لە بتوانێت بڕیار بدات و دروست بکات.
Watch 2:25-7:41: JUMP, JUMP_NEG, HALT and a loop.
لە 2:25 تا 7:41 سەیر بکە: JUMP، JUMP_NEG، HALT و .
Another design: one accumulatorدیزاینێکی تر: یەک تۆمارگەی کۆکەرەوە
The course slides draw a slightly different CPU. Memory is a numbered list of places, 00 to 99, each holding a number. Instead of R1, R2 and R3 the CPU has one main register, the accumulator (ACC), which collects the results. So each instruction names only a memory address.
سلایدەکانی وانەکە کەمێک جیاواز دەکێشن. لیستێکی ژمارەدارە لە شوێنەکان، لە 00 تا 99، کە هەر شوێنێکیان ژمارەیەک هەڵدەگرێت. لە جیاتی R1، R2 و R3، یەک سەرەکیی هەیە، (ACC)، کە ئەنجامەکان کۆ دەکاتەوە. بۆیە هەر تەنها ناونیشانێکی ناو دەبات.
| Addressناونیشان | Contentsناوەڕۆک |
|---|---|
| 0 | LOAD 4 |
| 1 | ADD 5 |
| 2 | STORE 6 |
| 3 | — |
| 4 | 3 |
| 5 | 6 |
| 6 | (empty)(بەتاڵ) |
| Stepهەنگاو | Instruction | What happensچی ڕوو دەدات | ACC |
|---|---|---|---|
| 1 | LOAD 4 | Copy the value at address 4 into ACC.بەهای ناونیشانی 4 کۆپی دەکرێت بۆ ناو ACC. | 3 |
| 2 | ADD 5 | Add the value at address 5 to ACC: .بەهای ناونیشانی 5 بۆ ACC زیاد دەکرێت: . | 9 |
| 3 | STORE 6 | Copy ACC into address 6.ACC کۆپی دەکرێت بۆ ناونیشانی 6. | 9 |
It is the same idea as our R1–R3 model: bring numbers in from memory, let the ALU work, write the result back. Only the way registers are named differs. Real CPUs have many general-purpose registers.
ئەمە هەمان بیرۆکەی نموونەی R1 تا R3ـە: ژمارەکان لە بهێنە ژوورەوە، با کار بکات، ئەنجامەکە بنووسەرەوە. تەنها شێوەی ناونانی جیاوازە. ڕاستەقینە چەندین هەیە.
From your code to machine instructionsلە کۆدەکەتەوە بۆ ڕێکارنامەکانی ئامێر
Nobody writes LOAD and STORE by hand for an app. A programmer writes one line such as total = a + b in a high-level language. A translator program — a compiler or an interpreter — turns it into machine instructions very much like our four:
کەس بۆ بە دەست LOAD و STORE نانووسێت. یەک دێڕی وەک total = a + b بە دەنووسێت. وەرگێڕ — یان — دەیکات بە ئامێر کە زۆر لە چوار ئێمە دەچن:
total = a + b
↓ compiler or interpreter
LOAD a → R1
LOAD b → R2
R1 + R2 → R3
STORE R3 → totalExplain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 1
Source code: easy for people to read.
: بۆ مرۆڤ ئاسانە بۆ خوێندنەوە.
- Lineدێڕی 5-8
Machine instructions (shown with words; in memory they are stored as bits, 0s and 1s).
ئامێر (بە وشە نیشان دراون؛ لە وەک ، واتە 0 و 1، هەڵدەگیرێن).
In memory each machine instruction is a pattern of bits — this is machine code. Why bits can stand for numbers and instructions is explained in Number systems and place value. How the translation itself works is taught in What is programming? and Compilers and interpreters.
لە هەر ئامێر نەخشێکە لە — ئەمە پێی دەوترێت . بۆچی دەتوانن ژمارە و نیشان بدەن لە سیستەمە ژمارەییەکان و بەهای خانەیی ڕوون کراوەتەوە. چۆنیەتیی وەرگێڕانەکە خۆی لە بەرنامەسازی چییە؟ و کۆمپایلەرەکان و ئینتەرپرێتەرەکان دەخوێندرێت.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | What is trueڕاستییەکە |
|---|---|
| «The STORE command runs the program.»« STORE کارا دەکات.» | STORE only copies a register into memory. The program runs because every instruction goes through fetch, decode and execute, one after another.STORE تەنها کۆپی دەکات بۆ . جێبەجێ دەبێت چونکە هەموو ، یەک لە دوای یەک، بە هێنان، شیکردنەوە و جێبەجێکردندا تێدەپەڕێت. |
| «The user types the instructions into RAM with the keyboard.»« بە دەنووسێتە ناو .» | The operating system copies a program from storage into RAM when you open it. The keyboard gives the program data. کاتێک دەکەیتەوە لە کۆپیی دەکات بۆ . دەداتە . |
| «Main memory (RAM) is part of the CPU», as some diagrams draw it.« () بەشێکە لە »، وەک هەندێک وێنە دەیکێشن. | RAM is outside the CPU and reached through the buses. Only the registers (and the cache) are inside the CPU. لە دەرەوەی و لە ڕێگەی پێی دەگەیەنرێت. تەنها (و کاش) لەناو . |
| «The PC holds the instruction being run.»«PC ئەو هەڵدەگرێت کە جێبەجێ دەکرێت.» | The IR holds that instruction. The PC holds the address of the next one.IR ئەو هەڵدەگرێت. PC ناونیشانی دواتر هەڵدەگرێت. |
| «The ALU fetches and decodes the instructions.»« دەهێنێت و شی دەکاتەوە.» | The control unit fetches and decodes; the ALU only calculates and compares. دەهێنێت و شی دەکاتەوە؛ تەنها حیساب و بەراورد دەکات. |
| «LOAD moves the number out of RAM, so A1 is empty afterwards.»«LOAD ژمارەکە لە دەردەهێنێت، بۆیە دواتر A1 بەتاڵ دەبێت.» | LOAD copies. A1 still holds 5 after LOAD A1 → R1.LOAD کۆپی دەکات. دوای LOAD A1 → R1 هێشتا A1 ژمارە 5 هەڵدەگرێت. |
Exercisesڕاهێنانەکان
RAM starts with A1 = 9 and A2 = 4. Trace this program and give R1, R2, R3, A4 and the PC at the end.
بە A1 = 9 و A2 = 4 دەست پێ دەکات. ئەم هەنگاو بە هەنگاو بگرەوە و لە کۆتاییدا R1، R2، R3، A4 و PC بنووسە.
0: LOAD A1 → R1
1: LOAD A2 → R2
2: R1 − R2 → R3
3: STORE R3 → A4Hintئاماژە
Use a trace table like the one in «The run as a table».
وەک ئەوەی بەشی «جێبەجێبوونەکە وەک خشتە» بەکار بهێنە.
Show answerوەڵامەکە پیشان بدە
R1 = 9, R2 = 4, R3 = 9 − 4 = 5, A4 = 5, PC = 4 (four instructions were fetched, from addresses 0 to 3). A1 and A2 still hold 9 and 4.
R1 = 9، R2 = 4، R3 = 9 − 4 = 5، A4 = 5، PC = 4 (چوار هێنران، لە ناونیشانی 0 تا 3). A1 و A2 هێشتا 9 و 4 هەڵدەگرن.
A1 = 3, A2 = 4 and A3 = 5. Using only the model's four instructions and R1–R3, write a program that stores A1 + A2 + A3 in A4. (Careful: the add instruction always adds R1 and R2 into R3.)
A1 = 3، A2 = 4 و A3 = 5. تەنها بە چوار نموونەکە و R1 تا R3، بنووسە کە A1 + A2 + A3 لە A4ـدا هەڵبگرێت. (ئاگاداربە: کۆکردنەوە هەمیشە R1 و R2 کۆ دەکاتەوە و دەیخاتە R3.)
Hintئاماژە
Store the first sum somewhere, then load it back.
کۆی یەکەم لە شوێنێک هەڵبگرە، پاشان بیهێنەرەوە.
Show answerوەڵامەکە پیشان بدە
0: LOAD A1 → R1
1: LOAD A2 → R2
2: R1 + R2 → R3 (R3 = 7)
3: STORE R3 → A4 (A4 = 7 for now)
4: LOAD A4 → R1 (R1 = 7)
5: LOAD A3 → R2 (R2 = 5)
6: R1 + R2 → R3 (R3 = 12)
7: STORE R3 → A4 (A4 = 12)The model has no instruction that copies R3 into R1, so the half-way result goes to RAM and comes back. That is eight instructions, so eight fetch–decode–execute cycles. A real instruction set has a «move» instruction that saves two of them.
نموونەکە هیچ نییە کە R3 کۆپی بکات بۆ R1، بۆیە ئەنجامی نیوەڕێ دەچێتە و دەگەڕێتەوە. ئەمە هەشت ، واتە هەشت جار هێنان، شیکردنەوە و جێبەجێکردن. ڕاستەقینە «گواستنەوە»ـی هەیە کە دوو کەم دەکاتەوە.
In the slide's machine, address 4 now holds 10 and address 5 holds 15. The program is still LOAD 4, ADD 5, STORE 6. What is in ACC after each step, and what is in address 6 at the end?
لە سلایدەکەدا، ئێستا ناونیشانی 4 ژمارە 10 و ناونیشانی 5 ژمارە 15 هەڵدەگرێت. هێشتا LOAD 4، ADD 5، STORE 6ـە. دوای هەر هەنگاوێک ACC چی هەڵدەگرێت؟ لە کۆتاییدا چی لە ناونیشانی 6ـدایە؟
Show answerوەڵامەکە پیشان بدە
After LOAD 4: ACC = 10. After ADD 5: ACC = 10 + 15 = 25. After STORE 6: ACC stays 25 and address 6 holds 25.
دوای LOAD 4: ACC = 10. دوای ADD 5: ACC = 10 + 15 = 25. دوای STORE 6: ACC هەر 25 دەمێنێتەوە و ناونیشانی 6 ژمارە 25 هەڵدەگرێت.
Rewrite the «larger number» steps so that for two equal numbers the program says that they are equal.
هەنگاوەکانی «ژمارە گەورەترەکە» بنووسەرەوە بە شێوەیەک کە بۆ دوو ژمارەی یەکسان بڵێت یەکسانن.
Show answerوەڵامەکە پیشان بدە
1. Input number1
2. Input number2
3. If number1 = number2, output "equal"
4. Otherwise, if number1 > number2, output number1
5. Otherwise, output number2Check «equal» first; only then compare which is larger.
سەرەتا «یەکسان» بپشکنە؛ ئینجا بەراورد بکە کامیان گەورەترە.
A classmate writes: «LOAD brings data into the CPU and STORE runs the program.» Which half is right? Rewrite the wrong half correctly in one sentence.
هاوپۆلێک دەنووسێت: «LOAD دەهێنێتە ناو و STORE کارا دەکات.» کام نیوەی ڕاستە؟ نیوە هەڵەکە لە یەک ڕستەدا بە ڕاستی بنووسەرەوە.
Show answerوەڵامەکە پیشان بدە
The first half is right. Correct second half: «STORE copies a value from a register back into memory; the program runs because the control unit fetches, decodes and executes every instruction in turn.»
نیوەی یەکەم ڕاستە. نیوەی دووەم بە ڕاستی: «STORE بەهایەک لە دەگەڕێنێتەوە بۆ ؛ جێبەجێ دەبێت چونکە هەموو بە نۆرە دەهێنێت، شی دەکاتەوە و جێبەجێ دەکات.»
Summaryپوختە
- A program is only a list of instructions. When you open it, the operating system copies it from storage into RAM.
- RAM holds instructions and data at numbered addresses. Registers are tiny, fast cells inside the CPU; the ALU calculates on them.
- LOAD copies from RAM into a register, STORE copies from a register into RAM, and the ALU adds or subtracts registers.
- takes four instructions:
LOAD A1 → R1,LOAD A2 → R2,R1 + R2 → R3,STORE R3 → A3. - Every instruction goes through the machine cycle: fetch, decode, execute (and store). The PC points to the next instruction; the IR holds the current one.
- High-level code is translated into machine instructions by a compiler or an interpreter.
- تەنها لیستێکی . کاتێک دەیکەیتەوە، لە کۆپیی دەکات بۆ .
- و لە ناونیشانی ژمارەداردا هەڵدەگرێت. خانەی بچووک و خێران لەناو ؛ حیسابیان لەسەر دەکات.
- LOAD لە کۆپی دەکات بۆ ، STORE لە کۆپی دەکات بۆ . کۆ دەکاتەوە یان لێک دەردەکات.
- چوار دەخوازێت:
LOAD A1 → R1،LOAD A2 → R2،R1 + R2 → R3،STORE R3 → A3. - هەموو بە تێدەپەڕێت: هێنان، شیکردنەوە، جێبەجێکردن (و هەڵگرتن). PC ئاماژە بە دواتر دەکات؛ IR ئەو هەڵدەگرێت کە ئێستا جێبەجێ دەکرێت.
- کۆدی لە لایەن یان دەکرێت بە ئامێر.
Does STORE run the program?ئایا STORE بەرنامەکە کارا دەکات؟
No. STORE copies a register into memory. Every instruction runs through the same fetch–decode–execute cycle.
نەخێر. STORE کۆپی دەکات بۆ . هەموو بە هەمان (هێنان، شیکردنەوە، جێبەجێکردن) تێدەپەڕێت.
Why does adding R1 and R2 need no bus?بۆچی کۆکردنەوەی R1 و R2 پێویستی بە هیچ تێپەڕگەیەک نییە؟
Both registers and the ALU are inside the CPU. Buses are needed only to reach RAM or devices.
هەردوو و لەناو . تەنها بۆ گەیشتن بە یان ئامێرەکان پێویستن.
What would happen if the PC never added 1?ئەگەر PC هەرگیز یەک زیاد نەکات چی ڕوو دەدات؟
The CPU would fetch the same instruction again and again and the program would never move on.
هەمان جار لە دوای جار دەهێنێت و هەرگیز بەرەو پێش ناچێت.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
A tiny model computer runs a short program: RAM, registers, the bus and the instruction set working together, step by step.
نموونەیی بچووک کورت جێبەجێ دەکات: ، ، و هەنگاو بە هەنگاو پێکەوە کار دەکەن.
The eChalk simulation that the lesson's model computer is redrawn from.
هاوشێوەکردنەکەی eChalk؛ نموونەیی ئەم وانەیە لەسەر ئەو دووبارە کێشراوەتەوە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Bits, Bytes and Storage Unitsبیتەکان، بایتەکان و یەکەکانی خەزنکردن
Related lecturesوانە پەیوەندیدارەکان
- The Parts of a Computer Systemپارچەکانی سیستەمی کۆمپیوتەر
- Memory: RAM, ROM and Cacheبیرگە: RAM، ROM و کاش
- The CPU: Control Unit, ALU and CoresCPU: یەکەی جڵەوکردن، ALU و ناوکەکانی پرۆسێسەر
- Processor Speed, Cache, GPUs and Coolingخێرایی پرۆسێسەر، کاش، GPU و ساردکردنەوە
- Bits, Bytes and Storage Unitsبیتەکان، بایتەکان و یەکەکانی خەزنکردن
- What Is Programming?بەرنامەسازی چییە؟
- How Code Becomes a Running Program: Compilers and Interpretersچۆن کۆد دەبێت بە بەرنامەیەک کە کار دەکات: کۆمپایلەرەکان و ئینتەرپرێتەرەکان
- Algorithms, Pseudocode and Flowchartsئەلگۆریزمەکان، نیمچەکۆد و هێڵکارییەکانی ڕەوت
- Number Systems and Place Valueسیستەمە ژمارەییەکان و بەهای خانەیی
- Programming Languages and Algorithmsزمانەکانی بەرنامەسازی و ئەلگۆریزمەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- Wikipedia: Central processing unit (instruction cycle, program counter, registers, ALU)
- Wikipedia: Instruction cycle (PC, MAR, MDR, CIR/IR in the fetch stage)
- Wikipedia: System bus (data, address and control bus)
- eChalk: How does a computer run a program? (the video the owner's paper explains)
- Intel: What is clock speed?
- Microsoft Learn: Windows on Arm (x86/x64 and Arm processors)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.