Skip to content

من الترانزستورات إلى المعالج

مقدمة

كيف "يفكر" الحاسوب؟ ربما تعرف أن المعالج هو "الدماغ" للحاسوب، لكن كيف يعمل هذا الدماغ فعلياً؟ كيف يتحول من معدن وبلاستيك إلى جهاز ذكي قادر على تنفيذ البرامج ومعالجة البيانات؟ يأخذك هذا الفصل من الترانزستورات الأكثر أساسية إلى فهم مبادئ بناء المعالج.

ماذا ستتعلم في هذه المقالة؟

  • فهم المصطلحات: "تردد المعالج"، "متعدد النوى"، "مجموعة التعليمات" لن تكون ألغازاً بعد الآن
  • منظور تنفيذ الكود: رؤية كيف يمر سطر كود من خلال الجلب، الترميز، التنفيذ، الكتابة الراجعة
  • التفكير في طبقات التجريد: فهم كيف تخدم كل طبقة الطبقة العليا
الفصلالمحتوىالمفهوم الأساسي
الفصل 1الترانزستوراتمفاتيح العالم الرقمي
الفصل 2البوابات المنطقيةالتنفيذ الفيزيائي للمنطق البوليني
الفصل 3الوحدات الوظيفيةالجامعات، المسجلات، المُختارات
الفصل 4نواة المعالجالجلب، الترميز، التنفيذ، الكتابة الراجعة

0. نظرة عامة: من الرمال إلى الذكاء

قدرة "التفكير" لدى الحواسيب الحديثة تنبع من شيء بسيط جداً: المفتاح.

عندما يمر التيار عبر مفتاح، يمثل "1"؛ عندما لا يمر، "0". إذا كان لدينا مليارات من هذه المفاتيح، ويمكننا جعل مخرج مفتاح يتحكم في مفتاح آخر، يمكننا بناء شبكات منطقية معقدة بشكل لا يصدق.

من الرمال إلى الذكاء، أربع طبقات:

تفكيك كل طبقة

  • الطبقة 1: الترانزستورات (مليارات) -- "المفتاح" الأكثر أساسية. MOSFET: تطبيق جهد على البوابة يسمح بالتدفق بين المصب والمصدر
  • الطبقة 2: البوابات المنطقية (مليارات) -- ترانزستورات متصلة تشكل AND، OR، NOT، XOR -- رياضيات بول على الدوائر
  • الطبقة 3: الوحدات الوظيفية (مئات) -- تجميع البوابات: جامعات، مُختارات، مسجلات
  • الطبقة 4: نواة المعالج (1-128 نواة) -- مركز القيادة: جلب، ترميز، تنفيذ، كتابة راجعة

1. الترانزستورات: مفاتيح العالم الرقمي

MOSFET transistor diagram -- click to toggle Gate voltage
Source
Source
Gate0
Open -> output 0
Drain
Drain
👆 Click to toggle Gate voltage

1.1 ما هو الترانزستور؟

الترانزستور جهاز أشباه موصلات يمكن تجريده كـ "مفتاح" مثالي:

  • المصدر (Source) و المصب (Drain): كطرفي أنبوب
  • البوابة (Gate): الصمام الذي يتحكم بالتدفق

الفرق الجوهري: نتحكم بـ الجهد وليس باليد. عندما يمكن لمفتاح أن يُتحكم بإشارة كهربائية من مفتاح آخر، نعبر الهوة من "التدخل البشري" إلى "الحساب التلقائي".

1.2 كيف تُمثّل 0 و 1؟

  • جهد عالٍ (مثال: 3.3V) = منطقي 1
  • جهد منخفض (قريب من 0V) = منطقي 0

1.3 تطور عدد الترانزستورات

العامالمعالجالترانزستوراتالعملية
1971Intel 40042,30010um
1993Intel Pentium3.1M800nm
2006Core 2 Duo291M65nm
2020Apple M116B5nm
2023Apple M3 Max92B3nm

2. البوابات المنطقية: الحساب بالمفاتيح

Four Basic Logic GatesThe building blocks of all digital computing
ANDAND gate
Operation:A ∧ B
Outputs 1 only when both inputs are 1
Series switches: both switches must be closed
Truth table
ABOutput
000
010
100
111
OROR gate
Operation:A ∨ B
Outputs 1 when at least one input is 1
Parallel switches: either switch can close the circuit
Truth table
ABOutput
000
011
101
111
NOTNOT gate
Operation:¬A
Inverts the input: 0 becomes 1, 1 becomes 0
Inverter: on becomes off, off becomes on
Truth table
AOutput
01
10
XORXOR gate
Operation:A ⊕ B
Outputs 1 only when the two inputs are different
Difference detector: different means true
Truth table
ABOutput
000
011
101
110
Core idea: Logic gates turn physical circuit on/off states into mathematical true/false operations. They are the bridge from hardware to software logic.

2.1 البوابات الأساسية

  • AND: جميع المدخلات يجب أن تكون 1 ليكون المخرج 1
  • OR: مدخل واحد 1 كافٍ ليكون المخرج 1
  • NOT: يعكس المدخل
  • XOR: المخرج 1 عندما تختلف المدخلان

2.3 الجمع بالبوابات المنطقية

XOR واحد (للمجموع) + AND واحد (للحمل) = نصف جامع (Half Adder).

Half Adder -- Interactive DemoClick inputs A and B to see the result for one binary column
+=00
▲ Carry: pass a 1 to the column on the left ▲ Sum: the digit written in this column
0 + 0 = 0. Write 0 in this column, with no carry.
All possible cases
ABWrite (sum)Carry
0000
0110
1010
1101

Look closely at the table and two patterns appear:

  • The sum column is 1 only when A and B are different. This is XOR.
  • The carry column is 1 only when A and B are both 1. This is AND.
The circuit is connected like this:
A = 0
B = 0
XOR gate
Different -> 1
Output: 0
AND gate
All 1 -> 1
Output: 0
Sum
0
Carry
0

نحتاج الجامع الكامل (Full Adder) الذي يقبل ثلاث مدخلات للجمع متعدد الأرقام.

Full Adder -- Interactive DemoA full adder adds one more input: carry-in (Cin) from the lower bit. Click the three inputs to try it.
++=01
ABCarry-inCarrySum
1 + 0 + 0 = 1. Write 1 in this column, with no carry.
Compared with a half adder: A full adder adds a third input: carry-in (Cin). In multi-bit addition, each column adds A, B, and the carry from the column on the right.
All 8 cases (3 inputs -> 2³ = 8)
ABCinSumCarry
00000
00110
01010
01101
10010
10101
11001
11111
Inside a full adder = two half adders in series
Step 1: Half adder 1
First calculate A + B
A = 1B = 0
Intermediate sum: 1Carry 1: 0
Step 2: Half adder 2
Add the intermediate sum and carry-in
Intermediate sum = 1Cin = 0
Sum: 1Carry 2: 0
Step 3: Merge carries
If either carry path is 1, carry 1 into the next higher bit.
Carry 1 = 0Carry 2 = 0
Final carry: 0
Ripple Carry AdderCascade multiple full adders to perform multi-bit binary addition
CascadeLower-bit Cout connects to higher-bit Cin
RippleCarry propagates bit by bit like a wave
OverflowThe highest bit produces a carry beyond the range
Bits:
+=13
A0111(7)
B0110(6)
=1101(13)
Adder cascadeHover to inspect each bit calculation
Bit 0Half adder
A1B0
Sum1Cout0
Bit 1Full adder
A1B1Cin0
Sum0Cout1
Bit 2Full adder
A1B1Cin1
Sum1Cout1
Bit 3Full adder
A0B0Cin1
Sum1Cout0
Overall calculation
Input:A = 7 (0111), B = 6 (0110)
Process:Start at bit 0, compute each sum and carry, and propagate carries toward higher bits.
Result:1101 = 13
Core idea: Carry ripples from the lowest bit to the highest bit, which is why this circuit is called a ripple carry adder. More bits increase delay, but the circuit stays simple.
Complete Adder DemoFrom logic gates to multi-bit addition -- abstraction layer by layer
Layer 1: Logic gates
The basic operation units. Each gate performs one Boolean operation.
AND gateOutputs 1 only when all inputs are 1
OR gateOutputs 1 when any input is 1
XOR gateOutputs 1 when inputs differ
&
AND gateA AND B
0001
>=1
OR gateA OR B
0111
=1
XOR gateA XOR B
0110
1
NOT gateNOT A
10
Core idea: Logic gates turn voltage levels (0/1) into Boolean operations (false/true). They are where hardware starts implementing math.
Abstraction layers
Logic gates
Half adder
⊞⊞Full adder
[]Multi-bit adder
CPUALU/CPU

3. الوحدات الوظيفية: تجميع البوابات المنطقية

الوحدةالمهمةتشبيه
الجامعمحرك حسابيمِعداد لا يتعب
المُختار (MUX)التحكم بتدفق البياناتمفتح سكة حديد
فاك الشفرةترجمة التعليمات الثنائيةمحل شفرات
قلاب (Flip-Flop)تسجيل الحالةأرجوحة تحافظ على وضعها
Common Functional Units -- switch modules to see how they work
Multiplexer (MUX): like a railway switch, it uses the select signal to decide which data input passes through.
Data 0 (D0)
Data 1 (D1)
MUX
Select (Sel)
Output (Out)0

The select signal is 0, so the output equals data 0 (D0): 0

3.1 المسجلات: تخزين البيانات

CPU Register FileHigh-speed storage inside the CPU
Special Registers
PC
0x00401000
Program counter
IR
0x8B450008
Instruction register
MAR
0x00401000
Memory address register
MDR
0x00000000
Memory data register
ACC
0x0000001A
Accumulator
General Purpose Registers
RAX
0x00000000
Return value
RBX
0x00000000
Base register
RCX
0x00000000
Counter register
RDX
0x00000000
Data register
RSI
0x00000000
Source index
RDI
0x00000000
Destination index
RBP
0x00000000
Base pointer
RSP
0x7FFDE000
Stack pointer
Program Status Word (PSW / FLAGS)
CF0Carry flag
PF0Parity flag
AF0Auxiliary carry
ZF0Zero flag
SF0Sign flag
OF0Overflow flag
Registers vs Memory
FeatureRegisterMemory (RAM)
LocationInside the CPUOutside the CPU
Access speedFastest (< 1ns)Slower (50-100ns)
CapacityTiny (bytes)Large (GB)
RoleHold instructions, operands, and resultsStore programs and data
From Flip-Flops to Registers: The Feedback Loop of Memory
Change the data and observe it: without a clock signal, the output feeds back to the input and the closed loop preserves memory.
Data Bus (Data Input)
1
0
1
0
Gate
🔒
4-bit Register (Stored State)
0
0
0
0
Control Center
Try changing the left-side input. The register value is locked while the feedback loop is closed.

4. بنية المعالج: من الوحدات الوظيفية إلى المعالج

4.1 المكونات الرئيسية

  • ALU (الوحدة الحسابية المنطقية): تنفيذ العمليات
  • ملف المسجلات: تخزين مؤقت فائق السرعة
  • الناقل الداخلي: نقل البيانات بين الوحدات
  • وحدة التحكم: قراءة التعليمات، توليد إشارات التحكم
CPU Internal Microarchitecture
Click a module to see its subcircuits and how it works
CPU Core (Central Processing Unit)
Address Bus
Data Bus

Control Unit

Program Counter (PC)
Instruction Register (IR)
Instruction Decoder
Clock Generator
Control signals ↓

Register File

General Registers R0-R3
Accumulator (ACC)

Arithmetic Logic Unit (ALU)

Adder Circuit
Status Flags
Control Bus
🖱️

Click a module in the CPU diagram to explore its circuit-level implementation.

4.2 كيف ينفذ المعالج التعليمات؟

  1. الجلب (Fetch): قراءة التعليمة من الذاكرة
  2. الترميز (Decode): تحليل العملية المطلوبة
  3. التنفيذ (Execute): إجراء العملية في ALU
  4. الكتابة الراجعة (Write Back): كتابة النتيجة في مسجل أو ذاكرة
Detailed CPU Instruction Cycle Demo
CPU
Control Unit CU
PC256Program Counter
IRInstruction Register
MARMemory Address Register
MDRMemory Data Register
Arithmetic Logic Unit ALU
ACC0Accumulator
General Register File
R00
R10
R20
R30
Address Bus
Data Bus
Control Bus
Main Memory
0x100LOAD R0, [0x200]
 0x101LOAD R1, #7
 0x102ADD R0, R1
 0x103STORE [0x201], R0
Data Area
 0x51242
 0x5130
FetchFetch
DecodeDecode
ExecuteExecute
Write BackWrite Back
Step 0 / 32
Click "Clock Pulse" to step through execution, or "Auto Run" to play continuously.

خط الأنابيب: البحث عن أقصى كفاءة

بدلاً من انتظار تعليمة واحدة لإكمال المراحل الأربع قبل بدء التالية، يسمح خط الأنابيب بتداخلها.


5. الملخص: عبر طبقات التجريد

  1. الفيزياء الكلية: الرمال (ثاني أكسيد السيليكون)
  2. الفيزياء المجهرية: مليارات الترانزستورات
  3. الجبر الرقمي: بوابات AND/OR/NOT
  4. وحدات المعما الدقيقة: وحدات وظيفية
  5. البنية المعقدة: المعالج
  6. عالم التطبيقات: البرمجيات والإنترنت

تأمل أخير

ما يُسمى القوة الحسابية ليس سوى كميات هائلة من المفاتيح تعيد تنظيم نفسها في مساحة مغلقة؛ بإيقاع الساعة، تُنجز حسابات معقدة على هذه الرقاقة السيليكونية الصغيرة.

"الكمية تقود إلى قفزة نوعية" -- هذه العبارة تُثبت باستمرار في بنية الحاسوب.


قراءة إضافية

  • كتاب كلاسيكي: "Computer Organization and Design" - Patterson & Hennessy
  • محاكاة المنطق الرقمي: بناء جامع 8 بت
  • بنية متقدمة: ذاكرة تخزين مؤقت متعددة المستويات، تنفيذ خارج الترتيب، GPU
  • لغة التجميع: فهم كيف يتحول الكود عالي المستوى إلى تعليمات الآلة