Skip to content · ⁨الانتقال إلى المحتوى⁩

Processor Fundamentals · ⁨أساسيات المعالج⁩

A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩ · Topic 4 · ⁨الموضوع 4⁩

Video lesson for this topic · ⁨درس فيديو لهذا الموضوع⁩ Open the video page · ⁨افتح صفحة الفيديو⁩
21:32

عمارة فون نيومان

لمعظم التاريخ، كانت الآلة تقوم بوظيفة واحدة. نسيج نسج القماش. آلة حاسبة أجرت الجمع. لجعلها تقوم بشيء جديد، أعاد بناؤها. ثم جاءت عمارة بسيطة بشكل خادع…

English narration · English + 中文 subtitles burned in · ⁨سرد باللغة الإنجليزية · ترجمة مدمجة بالإنجليزية + الصينية⁩

4.1

Von Neumann architecture · ⁨معمارية فون نيومان⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding of the basic Von Neumann model for a computer system and the stored program concept
Show understanding of the purpose and role of registers, including the difference between general purpose and special purpose registers Special purpose registers including: • Program Counter (PC) • Memory Data Register (MDR) • Memory Address Register (MAR) • The Accumulator (ACC) • Index Register (IX) • Current Instruction Register (CIR) • Status Register
Show understanding of the purpose and roles of the Arithmetic and Logic Unit (ALU), Control Unit (CU) and system clock, Immediate Access Store (IAS)
Show understanding of how data are transferred between various components of the computer system using the address bus, data bus and control bus
Show understanding of how factors contribute to the performance of the computer system Including: • processor type and number of cores • the bus width • clock speed • cache memory
Understand how different ports provide connection to peripheral devices Including connection to: • Universal Serial Bus (USB) • High Definition Multimedia Interface (HDMI) • Video Graphics Array (VGA)
Describe the stages of the Fetch-Execute (F-E) cycle Describe and use 'register transfer' notation to describe the F-E cycle
Show understanding of the purpose of interrupts Including: • possible causes of interrupts • applications of interrupts • use of an Interrupt Service Routine (ISR) • when interrupts are detected during the fetch-execute cycle • how interrupts are handled
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
أظهر فهماً لنموذج فون نيومان الأساسي لنظام حاسوبي ومفهوم البرنامج المخزن
أظهر فهماً لغرض ودور المسجلات، بما في ذلك الفرق بين مسجلات الغرض العام ومسجلات الغرض الخاص المسجلات ذات الغرض الخاص تشمل: • عداد البرنامج (PC) • مسجل بيانات الذاكرة (MDR) • مسجل عنوان الذاكرة (MAR) • المُجمّع (ACC) • مسجل الفهرس (IX) • مسجل التعليمات الحالية (CIR) • مسجل الحالة
أظهر فهماً لغرض وأدوار وحدة الحساب والمنطق (ALU)، وحدة التحكم (CU) و** الساعة النظامية**، المخزن ذو الوصول الفوري (IAS)
أظهر فهماً لكيفية نقل البيانات بين مكونات نظام الحاسوب المختلفة باستخدام ناقل العناوين، ناقل البيانات وناقل التحكم
أظهر فهماً للعوامل التي تساهم في أداء نظام الحاسوب بما في ذلك: • نوع المعالج وعدد النوى • عرض الناقل • سرعة الساعة • ذاكرة الكاش
افهم كيف توفر المنافذ المختلفة اتصالاً بالأجهزة الطرفية بما في ذلك الاتصال بـ: • النقل التسلسلي العالمي (USB) • واجهة الوسائط عالية الوضوح (HDMI) • مصفوفة الرسوميات المرئية (VGA)
صف مراحل دورة جلب-تنفيذ (F-E) صف واستخدم رمز 'انتقال المسجل' لوصف دورة F-E
أظهر فهماً لغرض الأوامر الناقلة (Interrupts) بما في ذلك: • الأسباب المحتملة للأوامر الناقلة • تطبيقات الأوامر الناقلة • استخدام روتين خدمة الأوامر الناقلة (ISR) • متى يتم اكتشاف الأوامر الناقلة أثناء دورة جلب-تنفيذ • كيفية التعامل مع الأوامر الناقلة

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English
The fetch-decode-execute cycle

The Von Neumann architecture 冯·诺依曼体系结构 underlies almost every general-purpose computer:

  • a single memory — the Immediate Access Store 立即存取存储器 (IAS) — holds both program instructions and data (the stored program 存储程序 concept).
  • a processor 处理器 (CPU) fetches instructions from memory and runs them one at a time.
  • instructions run in order unless a branch changes the flow.

The stored-program idea is what makes a computer flexible: change the program and you change what it does, with no rewiring.

العربية
دورة جلب-فك تشفير-تنفيذ

تعتمد معمارية فون نيومان· على معظم حواسيب الأغراض العامة:

  • ذاكرة واحدة — ذاكرة الوصول الفوري (IAS) — تحتفظ بـ تعليمات البرنامج والبيانات (مفهوم البرنامج المخزن).
  • معالج (CPU) يستخرج التعليمات من الذاكرة وينفذها واحدة تلو الأخرى.
  • تعمل التعليمات بترتيب محدد إلا إذا غيّر فرع تدفق التنفيذ.

فكرة البرنامج المخزن هي ما يجعل الحاسوب مرناً: غيّر البرنامج وتغيّر وظيفته دون الحاجة لإعادة توصيل الأسلاك.

Explore · ⁨استكشف⁩

Tap the parts of a Von Neumann computer · ⁨اضغط على مكونات حاسوب فون نيومان⁩

Explore each block. The CPU (control unit, ALU, registers) talks to a single main memory over the buses — and that one shared memory for instructions AND data is the Von Neumann idea. · ⁨استكشف كل كتلة. تتواصل وحدة المعالجة المركزية (وحدة التحكم، وحدة الحساب والمنطق، المسجلات) مع ذاكرة رئيسية واحدة عبر الحواجز — وتُعد هذه الذاكرة المشتركة الواحدة للأوامر والبيانات هي فكرة فون نيومان.⁩

4.1

The CPU's main parts · ⁨الأجزاء الرئيسية للمعالج⁩

English

All of these parts sit inside one small chip. The diagram later in this section shows how they connect; the photo below shows the real thing.

Arithmetic and Logic Unit (ALU)

The ALU 算术逻辑单元 does the arithmetic (add, subtract, …) and logic (AND, OR, comparisons). It takes operands from registers 寄存器 and puts results back in a register.

Control Unit (CU)

The control unit 控制单元 decodes each instruction and sends the control signals to carry it out — opening data paths, telling the ALU what to do, and controlling memory reads and writes.

System clock

The clock sends a steady stream of pulses that keep the CPU in step. Each instruction takes a fixed number of cycles, and the clock speed 时钟频率 (e.g. 3.8 GHz) is one factor in performance.

"Explain how the CU and the system clock work together": the clock emits pulses at a fixed frequency; the control unit uses each pulse to move the fetch-execute cycle on by one step, sending its control signals in time with the pulses, so every part of the processor changes state together. A faster clock means more steps per second, up to the point where the circuits cannot settle between pulses.

Registers

Registers are tiny, very fast stores inside the CPU. The special purpose registers 专用寄存器 each have a fixed job in the cycle:

  • Program Counter 程序计数器 (PC) — the address of the next instruction.
  • Memory Address Register 内存地址寄存器 (MAR) — the address being read or written.
  • Memory Data Register 内存数据寄存器 (MDR) — the data going to or from memory.
  • Current Instruction Register 当前指令寄存器 (CIR) — the instruction being decoded.
  • Accumulator 累加器 (ACC) — the value the ALU is working on.
  • Status Register 状态寄存器 — holds flags 标志 (carry, zero, negative, overflow) used by branches. Each flag is one bit, set or cleared by the ALU after an operation: the zero flag after a comparison that matched, the carry flag when an addition overflowed the register, the negative flag when a result is negative. A conditional jump reads the flags to decide whether to branch, and an overflow flag can raise an interrupt.
  • Index Register 变址寄存器 — an offset added to an address in indexed addressing; incrementing it steps through an array one element at a time.

The "complete the table describing the role of each register" question wants one precise sentence per register in these terms: the PC holds the address of the next instruction to be fetched; the MAR holds the address of the location being read from or written to; the MDR holds the data or instruction just read from, or about to be written to, that location; the CIR holds the instruction currently being decoded and executed; the ACC holds the result of the last arithmetic or logic operation.

General-purpose registers 通用寄存器 are used by the programmer for temporary values during a calculation. Movements of data between registers and memory are written in register transfer 寄存器传送 notation — e.g. MAR ← [PC] ("copy the contents of PC into MAR").

العربية

جميع هذه الأجزاء تقع داخل شريحة صغيرة واحدة. يُظهر الرسم البياني لاحقاً في هذا القسم كيفية اتصالها؛ الصورة أدناه تُظهر الشريحة الحقيقية.

الجانب السفلي لرقاقة معالج Intel على خلفية بيضاء، مربع مسطح مغطى بشبكة من مئات وسادات الاتصال الذهبية الصغيرة التي تضغط على مقبس اللوحة الأم
معالج حديث: المعالج بالكامل هو شريحة صغيرة واحدة (هنا تظهر من الأسفل، مُظهرة-points الاتصال)
مقبس معالج مربع على لوحة أم، مع شبكة من الدبابيس الدقيقة ومقبض احتجاز معدني، محاط بمسارات الدوائر
مقبس المعالج المتوافق على اللوحة الأم: نقاط اتصال الشريحة تضغط على هذه الدبابيس

وحدة الحساب والمنطق (ALU)

تقوم وحدة ALU بالحساب (جمع، طرح، ...) والمنطق (AND, OR, مقارنات). تأخذ المعاملات من المسجلات وتضع النتائج مرة أخرى في مسجل.

وحدة التحكم (CU)

وحدة التحكم تفسر كل تعليمة وتُرسل إشارات التحكم لتنفيذها — فتح مسارات البيانات، إخبار ALU بما يجب فعله، والتحكم في قراءات وكتابات الذاكرة.

ساعة النظام

تُرسِل الساعة تدفقاً مستمراً من النبضات تبقي المعالج متناسقاً. تستغرق كل تعليمة عددًا ثابتًا من الدورات، وتعد سرعة الساعة (مثلاً 3.8 GHz) عاملاً في الأداء.

"اشرح كيف تعمل وحدة التحكم وساعة النظام معاً": تُصدر الساعة نبضات بتردد ثابت؛ تستخدم وحدة التحكم كل نبضة لتقدم دورة جلب-تنفيذ بخطوة واحدة، وترسل إشاراتها التحكمية في تزامن مع النبضات، بحيث يتغير حالة كل جزء من المعالج معاً. سرعة أعلى تعني خطوات أكثر في الثانية، حتى النقطة التي لا تستطيع فيها الدوائر الاستقرار بين النبضات.

المسجلات

المسجلات مخازن صغيرة وسريعة جداً داخل المعالج. كل مسجل purpose خاص له وظيفة ثابتة في الدورة:

  • عداد البرنامج (PC) — عنوان التعليمة التالية.
  • مسجل عنوان الذاكرة (MAR) — العنوان الذي يتم قراءته أو كتابته.
  • مسجل بيانات الذاكرة (MDR) — البيانات المتجهة إلى الذاكرة أو القادمة منها.
  • مسجل التعليمة الحالية (CIR) — التعليمة التي يتم تفسيرها حالياً.
  • المجمّع (ACC) — القيمة التي يعمل عليها ALU.
  • مسجل الحالة — يحتوي على علامات (الحمل، الصفر، السالب، التفوق) المستخدمة في الفروع. كل علامة بت واحد، يتم تعيينه أو إلغاؤه بواسطة ALU بعد عملية: علامة الصفر بعد مقارنة تطابقت، علامة الحمل عند تفوق الجمع عن المسجل، علامة السالب عندما يكون النتيجة سالبة. القفز الشرطي يقرأ العلامات لقرارة الفرع، ويمكن أن ترفع علامة التفوق مقاطعة.
  • مسجل المؤشر — إزاحة تُضاف إلى العنوان في العنونة بالمؤشر؛ زيادته ينقل عبر مصفوفة عنصرًا واحدًا في كل مرة.

سؤال "أتمم الجدول الذي يصف دور كل مسجل" يتطلب جملة دقيقة واحدة لكل مسجل بهذه المصطلحات: PC يحمل عنوان التعليمة التالية سيتم جلبها؛ MAR يحمل عنوان الموقع الذي يتم القراءة منه أو الكتابة فيه؛ MDR يحمل البيانات أو التعليمة التي تم قراءتها للتو من، أو سيتم كتابتها إلى، ذلك الموقع؛ CIR يحمل التعليمة جاري تفسيرها وتنفيذها حالياً؛ ACC يحمل نتيجة آخر عملية حسابية أو منطقية.

تُستخدم المسجلات متعددة الأغراض من قبل المبرمج لتخزين القيم المؤقتة أثناء الحساب. تُكتب حركات البيانات بين المسجلات والذاكرة باستخدام رمز نقل المسجل — على سبيل المثال MAR ← [PC] ("نسخ محتويات PC إلى MAR").

مخطط كتلي لمعالف فون نيومان يُظهر PC وMAR وMDR وCIR وACC وسجل الحالة ووحدة التحكم وALU وساعة النظام، متصلة بالذاكرة الرئيسية والإدخال/الإخراج عبر ناقلات العنوان والبيانات والتحكم
معالف فون نيومان: المسجلات ووحدة التحكم وALU مرتبطة عبر الناقلات
Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
Von Neumann architecture/vɒn ˈnɔɪmən ˈɑːkɪtektʃə/ عمارة فون نيومان
Immediate Access Store/ɪˈmiːdɪət ˈækses stɔː/ ذاكرة الوصول الفوري
stored program/stɔːd ˈprəʊɡræm/ برنامج مخزن
processor/ˈprəʊsesə/ المعالج
arithmetic and logic unit/ˌærɪθˈmetɪk ənd ˈlɒdʒɪk ˈjuːnɪt/ وحدة الحساب والمنطق
ALU/ˌeɪ el ˈjuː/ وحدة الحساب والمنطق (ALU)
4.1

Buses · ⁨الناقلات⁩

English

Three internal buses 总线 (sets of parallel wires) connect the parts:

  • address bus 地址总线 — carries the memory address. One-way (CPU → memory).
  • data bus 数据总线 — carries the data. Two-way.
  • control bus 控制总线 — carries control signals (read, write, interrupt). Two-way.

An $n$-bit address bus can reach $2^{n}$ memory locations. The data-bus width sets how many bits move per access (often the word size).

العربية

ثلاث ناقلات داخلية (مجموعات من الأسلاك المتوازية) تربط الأجزاء:

  • ناقل العنوان — ينقل عنوان الذاكرة. ذو اتجاه واحد (CPU → الذاكرة).
  • ناقل البيانات — ينقل البيانات. ثنائي الاتجاه.
  • ناقل التحكم — ينقل إشارات التحكم (قراءة، كتابة، انقطاع). ثنائي الاتجاه.

يمكن لـ ناقل العناوين بسعة $n$ بت الوصول إلى $2^{n}$ موقع في الذاكرة. تحدد سعة ناقل البيانات عدد البتات المنقولة في كل وصول (غالبًا ما تكون حجم الكلمة).

CPU والذاكرة والإدخال/الإخراج تتصل جميعها بناقل العناوين (ذو اتجاه واحد) وناقل البيانات وناقل التحكم داخل ناقل النظام
الناقلات الثلاثة لنظام الاتصال التي تربط CPU والذاكرة والإدخال/الإخراج
لوحة أم رئيسية تُرى من الأعلى: مقبس CPU ومفتحات الذاكرة ومفتحات التوسعة متصلة عن طريق مسارات مطبوعة كثيفة
لوحة أم رئيسية: CPU والذاكرة وI/O جميعها تستقر على مجموعة واحدة من الناقلات — وهي المسارات المطبوعة التي تمتد بينها
Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
buses/ˈbʌsɪz/ حواجز بيانات
address bus/əˈdres bʌs/ حاجز العناوين
data bus/ˈdeɪtə bʌs/ حاجز البيانات
word size/wɜːd saɪz/ حجم الكلمة
number of cores/ˈnʌmbə ɒv kɔːz/ عدد النوى
cores/kɔːz/ أنوية
amount of RAM/əˈmaʊnt ɒv ræm/ كمية ذاكرة الوصول العشوائي
4.1

What affects performance · ⁨ما يؤثر على الأداء⁩

English
  • clock speed — more cycles per second.
  • number of cores 核心 — a multi-core CPU runs several threads at once.
  • word size 字长 — a 64-bit CPU handles 64-bit chunks per cycle and can address far more memory than a 32-bit one.
  • amount of RAM 随机存取存储器 — more RAM holds more of the working set; too little forces the OS to page 页 to disk.
  • cache memory 高速缓存 size — more cache cuts average memory access time.
  • secondary storage 辅助存储器 type — an SSD loads programs far faster than an HDD.
  • bus width and speed — wider/faster buses move data more quickly.

Match the specs to the workload: a quad-core beats a dual-core on parallel work, but higher per-core speed wins on single-threaded work.

Each factor is a two-mark answer with a reason attached:

  • More cores: each core can fetch and execute its own instruction at the same time, so several programs, or the threads of one program, run in parallel. But a program must be written to use more than one core, so doubling the cores does not double the speed.
  • Higher clock speed: more fetch-execute cycles per second, so more instructions per second; the limit is the heat produced.
  • Wider bus: a wider data bus moves more bits in each transfer, so fewer transfers are needed for the same data; a wider address bus can address more memory locations.
  • Cache memory: a small, fast memory inside or next to the processor that keeps the instructions and data used most recently or most often. Reading them from cache is much faster than from RAM, so the processor spends less time waiting.

"Explain why the new computer performs better" is answered by comparing the two specifications line by line: a higher clock speed executes more instructions per second, more cores run more tasks at once, more cache means fewer slow accesses to RAM, and more RAM means fewer transfers to disk.

العربية
  • سرعة الساعة — دورات أكثر في الثانية.
  • عدد النوى — معالج متعدد النوى يشغل عدة خيوط عمل في وقت واحد.
  • حجم الكلمة — معالج 64-بت يتعامل مع كتل بحجم 64-بت لكل دورة ويمكنه معالجة ذاكرة أكبر بكثير من المعالج 32-بت.
  • كمية RAM — تزيد RAM من سعة تخزين مجموعة العمل؛ القليل منها يجبر نظام التشغيل على التبديل إلى القرص الصلب.
  • حجم ذاكرة الكاشي — زيادة الكاشي تقلل متوسط زمن الوصول للذاكرة.
  • نوع التخزين الثانوي — يحمّل SSD البرامج بشكل أسرع بكثير من HDD.
  • عرض وسرعة الناقل — الناقلات الأوسع والأسرع تنقل البيانات بسرعة أكبر.

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

كل عامل هو إجابة بعلامة اثنتين مع سبب مرفق:

  • مزيد من النوى: يمكن لكل نواة جلب وتنفيذ تعليماتها الخاصة في نفس الوقت، لذا تعمل عدة برامج أو خيوط عمل برنامج واحد بالتوازي. لكن يجب كتابة البرنامج لاستخدام أكثر من نواة واحدة، لذا مضاعفة النوى لا تضاعف السرعة.
  • سرعة ساعة أعلى: دورات جلب-تنفيذ أكثر في الثانية، لذا تعليمات أكثر في الثانية؛ والحد الأقصى هو الحرارة الناتجة.
  • ناقل أوسع: ناقل بيانات أوسع ينقل المزيد من البتات في كل نقل، لذا يُقلل عدد النقلات المطلوبة لنفس البيانات؛ ناقل عناوين أوسع يمكنه معالجة مواقع ذاكرة أكثر.
  • ذاكرة الكاشي: ذاكرة صغيرة وسريعة داخل أو بجانب المعالج تحتفظ بأحدث التعليمات والبيانات استخدامًا أو الأكثر تكرارًا. قراءتها من الكاشي أسرع بكثير من RAM، لذا يقضي المعالج وقتًا أقل في الانتظار.

"اشرح لماذا يقوم الكمبيوتر الجديد بأداء أفضل" تُجاب بمقارنة المواصفطين سطراً بسطر: سرعة ساعة أعلى تنفذ تعليمات أكثر في الثانية، نوى أكثر تشغل مهام أكثر في وقت واحد، كاشي أكبر يعني وصولات أبطأ أقل إلى RAM، وRAM أكبر يعني نقلات أقل إلى القرص.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
RAM/ræm/ ذاكرة RAM
page/peɪdʒ/ صفحة
cache memory/kæʃ ˈmeməri/ ذاكرة التخزين المؤقت
cache/kæʃ/ cache
secondary storage/ˈsekəndəri ˈstɔːrɪdʒ/ التخزين الثانوي
port/pɔːt/ منفذ
peripheral/pəˈrɪfərəl/ peripheral ( peripheral )
register transfer notation/ˈredʒɪstə ˈtrænsfɜː nəʊˈteɪʃn/ رمز انتقال المسجلات
interrupt service routine/ˈɪntərʌpt ˈsɜːvɪs ruːˈtiːn/ روتين خدمة الانقطاع
interrupt register/ˈɪntərʌpt ˈredʒɪstə/ مسجل الانقطاع
stack/stæk/ مكدس
assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ لغة التجميع
machine code/məˈʃiːn kəʊd/ كود الآلة
mnemonics/nɪˈmɒnɪks/ الاختصارات
assembler/əˈsemblə/ مبرمج
symbol table/ˈsɪmbl ˈteɪbl/ جدول الرموز
label/ˈleɪbl/ التسمية
forward references/ˈfɔːwəd ˈrefrənsɪz/ المرجعات الأمامية
opcode/ˈɒpkəʊd/ رمز العملية
4.1

Ports · ⁨المنافذ⁩

English

A port 端口 is a physical socket for connecting a peripheral 外围设备:

  • USB (Universal Serial Bus) — general-purpose (keyboards, drives, phones).
  • HDMI (High Definition Multimedia Interface) — digital video and audio to a screen.
  • VGA (Video Graphics Array) — older analogue video output to a monitor.
  • Ethernet (RJ-45) — wired LAN. Audio jacks — headphones/microphone.

Different ports use different signals, so an HDMI cable will not fit a USB socket. USB-C is unusual in carrying video, data and power.

"Explain how the computer connects to the monitor through HDMI": the HDMI port sends the video and the audio as one digital signal down a single cable, so no conversion to analogue is needed and the picture is not degraded; the cable carries high-definition resolutions and the monitor's own port decodes the signal. A USB device is plug-and-play: when it is connected the computer detects it, identifies it, loads or installs the driver it needs, and can supply it with power, all without a restart.

العربية

المنفذ هو مقبس فيزيائي لتوصيل جهاز طرفي:

  • USB (ناقل تسلسلي عالمي) — متعدد الأغراض (ألواح مفاتيح، محركات أقراص، هواتف).
  • HDMI (واجهة الوسائط عالية الدقة) — فيديو وصوت رقمي إلى شاشة.
  • VGA (مصفوفة رسوميات الفيديو) — خرج فيديو تناظري قديم إلى شاشات العرض.
  • Ethernet (RJ-45) — شبكة محلية سلكية. منافذ الصوت — سماعات الرأس/مايكروفون.

تستخدم منافذ مختلفة إشارات مختلفة، لذا لن يتناسب كابل HDMI مع مقبس USB. USB-C غير معتاد في حمل الفيديو والبيانات والطاقة.

"اشرح كيف يتصل الكمبيوتر بالشاشة عبر HDMI": يرسل منفذ HDMI الفيديو والصوت كإشارة رقمية واحدة عبر كابل واحد، لذا لا حاجة للتحويل إلى تناظري ولا يتدهور الصورة؛ يحمل الكابل دقة عالية وتقوم منفذ الشاشة بفك تشفير الإشارة. الجهاز USB شغّل واتصل: عند توصيله يكتشفه الكمبيوتر، ويتعرف عليه، ويحمل أو يثبت التعريف المطلوب له، ويمكنه تزويد بالطاقة، كل ذلك بدون إعادة تشغيل.

4.1

Fetch-Execute cycle · ⁨دورة الجلب والتنفيذ⁩

English

The CPU repeats the fetch-execute cycle 取指-执行周期, one run per machine instruction.

Fetch

  1. the PC's address is copied to the MAR.
  2. the PC is incremented to point to the next instruction.
  3. a read signal goes over the control bus.
  4. memory puts the instruction on the data bus.
  5. it is copied into the MDR, then into the CIR.

The exam asks for these steps in register transfer notation 寄存器传送记法, where [X] means the contents of register X and [[MAR]] means the contents of the memory location whose address is in the MAR:

The order matters: the PC is incremented straight after its address has been copied, so that a jump executed later can still overwrite it. During execution the same notation describes each instruction; for LDD 200, for example, MAR ← 200, MDR ← [[MAR]], ACC ← [MDR].

Decode

The CU decodes the instruction in the CIR — what operation, and which operands or addresses.

Execute

The CU carries it out: arithmetic/logic goes to the ALU (result to the ACC); a load/store moves data between memory and a register; a branch changes the PC. Then the cycle repeats.

العربية

يكرر المعالج دورة الجلب-التنفيذ، مرة واحدة لكل تعليمة آلية.

الجلب

  1. يُنسخ عنوان PC إلى MAR.
  2. يتم زيادة PC ليشير إلى التعليمة التالية.
  3. تذهب إشارة قراءة عبر ناقل التحكم.
  4. تضع الذاكرة التعليمة على ناقل البيانات.
  5. تُنسخ إلى MDR، ثم إلى CIR.

يسأل الامتحان عن هذه الخطوات بـرمز نقل المسجل، حيث [X] تعني محتويات المسجل X و[[MAR]] تعني محتويات موقع الذاكرة الذي يقع عنوانه في MAR:

MAR ← [PC]          the address of the next instruction goes to the MAR
PC  ← [PC] + 1      the PC now points to the following instruction
MDR ← [[MAR]]       the instruction at that address is read into the MDR
CIR ← [MDR]         the instruction is copied into the CIR for decoding

الترتيب مهم: يتم زيادة PC مباشرة بعد نسخ عنوانه، بحيث لا يزال بإمكان القفز المنفذ لاحقًا استبداله. أثناء التنفيذ يصف الرمز نفسه كل تعليمة؛ على سبيل المثال لـ LDD 200، لدينا MAR ← 200، MDR ← [[MAR]]، ACC ← [MDR].

نقلات مسجلات الجلب بالترتيب: 1 عنوان PC يذهب إلى MAR؛ 2 MRB يرسل العنوان إلى الذاكرة؛ 3 تعود التعليمة إلى MDR؛ 4 MDR ينسخها إلى CIR؛ وفي meantime يتم زيادة PC
نقلات المسجلات في الجلب: PC → MAR → الذاكرة → MDR → CIR، مع زيادة PC

فك التشفير

تقوم وحدة التحكم بفك تشفير التعليمات في مسجل CIR — ما هي العملية، وما هي المعاملات أو العناوين.

التنفيذ

تنفذها وحدة التحكم: العمليات الحسابية/المنطقية تُرسل إلى ALU (الناتج إلى ACC)؛ عملية التحميل/التخزين تنقل البيانات بين الذاكرة والمسجل؛ قفزة تغيير PC. ثم يتكرر الدورة.

مخطط انسيابي لدورة الاستخراج-التنفيذ من START: مرحلة الاستخراج (PC إلى MAR، زيادة PC، إشارة قراءة، ذاكرة إلى ناقل البيانات إلى MDR إلى CIR)، مرحلة فك التشفير، مرحلة التنفيذ، ثم التحقق من المقاطعات التي تعود إلى START
دورة الاستخراج-التنفيذ، مع التحقق من المقاطعات في كل مرة
Explore · ⁨استكشف⁩

The fetch-execute cycle · ⁨دورة جلب التنفيذ⁩

Tap round the loop the CPU repeats billions of times a second. Watch how fetch uses the PC/MAR/MDR/CIR registers, then decode and execute act on what was fetched. · ⁨اضغط حول الحلقة التي تكررها وحدة المعالجة المركزية مليارات المرات في الثانية. شاهد كيف يستخدم الجلب مسجلات PC/MAR/MDR/CIR، ثم فك التشفير والتنفيذ يؤثران على ما تم جلبه.⁩

Explore · ⁨استكشف⁩

The fetch–execute cycle · ⁨دورة جلب التنفيذ⁩

Step through how the CPU runs one instruction — fetch it from memory, decode it, then execute it, over and over. · ⁨مرر عبر كيفية تشغيل المعالج لم instruction واحدة — اجلبه من الذاكرة، شفره، ثم نفذه، مرارًا وتكرارًا.⁩

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
fetch-execute cycle/fetʃ ˈeksɪkjuːt ˈsaɪkl/ دورة جلب-تنفيذ
special purpose registers/ˈspeʃl ˈpɜːpəs ˈredʒɪstəz/ مسجلات ذات أغراض خاصة
Program Counter/ˈprəʊɡræm ˈkaʊntə/ عداد البرنامج
Memory Address Register/ˈmeməri əˈdres ˈredʒɪstə/ مسجل عنوان الذاكرة
Memory Data Register/ˈmeməri ˈdeɪtə ˈredʒɪstə/ مسجل بيانات الذاكرة
Current Instruction Register/ˈkʌrənt ɪnˈstrʌkʃn ˈredʒɪstə/ مسجل التعليمات الحالية
accumulator/əˈkjuːmjʊleɪtə/ المُجمِّع
Status Register/ˈsteɪtəs ˈredʒɪstə/ مسجل الحالة
flags/flæɡz/ العلامات
4.1

Interrupts · ⁨المقاطعات⁩

English

An interrupt 中断 is a signal that pauses the normal cycle so the CPU can handle an urgent event (a key press, a packet arriving, a hardware fault, division by zero, the OS timer).

Handling one:

  1. finish the current instruction.
  2. save the state (PC and registers).
  3. load the address of the interrupt service routine 中断服务程序 (ISR) into the PC and run it.
  4. the ISR handles the event.
  5. restore the saved state and carry on.

Interrupts let the system respond promptly without the CPU constantly checking devices, and are how the OS multitasks.

"Explain how an interrupt from an input device is detected and handled in the F-E cycle" is a four-mark answer with these points: the device sends an interrupt signal that sets the interrupt flag in the interrupt register 中断寄存器; the processor checks that register at the end of every fetch-execute cycle, after the current instruction has finished executing; if a flag is set and the interrupt has a higher priority than the current task, the contents of the PC and the other registers are saved onto the stack 栈; the address of the interrupt service routine is loaded into the PC and the routine runs; when it finishes, the saved values are restored from the stack and the interrupted program continues from where it stopped.

Causes worth naming: a hardware interrupt from a device (a key pressed, a printer buffer empty, a network packet arriving), a software interrupt from a fault (division by zero, an illegal instruction, arithmetic overflow), a timer interrupt from the operating system marking the end of a time slice, and a power failure warning.

العربية

المقطع هو إشارة توقف الدورة الطبيعية حتى يتمكن CPU من معالجة حدث طارئ (ضغط مفتاح، وصول حزمة بيانات، عطل في الأجهزة، القسمة على صفر، مؤقت نظام التشغيل).

معالجة واحدة:

  1. إكمال التعليمة الحالية.
  2. حفظ الحالة (PC والمسجلات).
  3. تحميل عنوان روتين خدمة المقاطعة (ISR) في PC وتشغيله.
  4. يقوم ISR بمعالجة الحدث.
  5. استعادة الحالة المحفوظة والاستمرار.

تسمح المقاطعات للنظام بالاستجابة بسرعة دون أن يفحص CPU الأجهزة باستمرار، وهي الطريقة التي يستخدمها نظام التشغيل لمتعدد المهام.

"اشرح كيف يتم اكتشاف المقطع القادم من جهاز إدخال ومعالجته في دورة F-E" إجابة مؤهلة بأربع نقاط: يرسل الجهاز إشارة مقطع تضع علم المقاطعة في مسجل المقاطعة؛ يفحص المعالج ذلك المسجل في نهاية كل دورة استخراج-تنفيذ، بعد انتهاء تنفيذ التعليمة الحالية؛ إذا تم تعيين العلم وكان للمقطع أولوية أعلى من المهمة الحالية، يتم حفظ محتويات PC والمسجلات الأخرى على الكدسة؛ يتم تحميل عنوان روتين خدمة المقاطعة في PC ويتم تشغيل الروتين؛ عند انتهائه، يتم استعادة القيم المحفوظة من الكدسة ويستمر البرنامج المقطوع من حيث توقف.

أسباب تستحق التسمية: مقطع أجهزة من جهاز (ضغط مفتاح، فارغ مخزن الطابعة، وصول حزمة شبكة)، مقطع برمجيات من خطأ (القسمة على صفر، تعليمة غير قانونية، فائض حسابي)، مقطع مؤقت من نظام التشغيل يحدد نهاية شريحة زمنية، وإنذار بانقطاع الطاقة.

مخطط انسيابي لمعالجة المقاطعات: يتوقف البرنامج الجاري، يكمل المعالج التعليمة الحالية، يحفظ حالته (PC والمُصَفِّرات) على المكدس، ينفذ روتين خدمة المقطع، يستعيد الحالة ويستأنف
كيف يندمج المقطع ضمن دورة الاستخراج-التنفيذ
Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
interrupt/ˈɪntərʌpt/ انقطاع
4.2

Assembly language and machine code · ⁨لغة التجميع والرمز الآلي⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding of the relationship between assembly language and machine code
Describe the different stages of the assembly process for a two-pass assembler Apply the two-pass assembler process to a given simple assembly language program
Trace a given simple assembly language program
Show understanding that a set of instructions are grouped Including the following groups: • Data movement • Input and output of data • Arithmetic operations • Unconditional and conditional instructions • Compare instructions
Show understanding of and be able to use different modes of addressing Including immediate, direct, indirect, indexed, relative
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
أظهر فهماً للعلاقة بين لغة التجميع وكود الآلة
وصف المراحل المختلفة لعملية التجميع لـ مُجمِّع ثنائي الممر تطبيق عملية المُجمِّع ثنائي الممر على برنامج لغة تجميع بسيطة معطاة
تتبع برنامج لغة تجميع بسيط معطى
إظهار الفهم بأن مجموعة من التعليمات تُجمَّع معًا بما في ذلك المجموعات التالية: • نقل البيانات • إدخال وإخراج البيانات • العمليات الحسابية • تعليمات غير مشروطة ومشروطة • تعليمات المقارنة
إظهار الفهم والقدرة على استخدام أوضاع العنونة المختلفة بما في ذلك الفورية، المباشرة، غير المباشرة، المؤشَّرة، النسبية

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

The CPU actually runs machine code 机器码 — bit patterns, specific to one architecture. Assembly language 汇编语言 is a readable form, with one instruction per machine instruction, written using mnemonics 助记符 like LDD, ADD, JMP. An assembler 汇编器 translates it to machine code.

Two-pass assembler

A two-pass assembler reads the source twice:

  • pass 1 builds a symbol table 符号表: each time a label 标签 (like LOOP:) appears, record its address; no code yet.
  • pass 2 generates code: translate each instruction, and when one refers to a label (like JMP LOOP), look up its address in the symbol table.

Two passes handle forward references 前向引用 (a jump to a label defined later).

Worked example. Apply the two-pass process to this program, whose first instruction is stored at address 100.

Pass 1 reads each line, counts the address it will occupy, and records every label in the symbol table: LOOP = 101 (the DEC line) and COUNT = 105 (the data line). No code is produced. Pass 2 reads the program again and translates each line into machine code, replacing each mnemonic by its opcode 操作码 and each symbolic address by the number from the symbol table: LDD COUNT becomes the opcode for LDD with operand 操作数 105, and JPN LOOP becomes the opcode for JPN with operand 101. The jump back to LOOP could have been resolved in one pass, but a jump forward to a label not yet seen could not, which is why the assembler makes two.

Example instruction set

Cambridge uses a small generic set, printed in the paper's reference table, with one general-purpose register, the accumulator (ACC), and an index register (IX). An operand written #n is a denary number, Bn a binary number and &n a hexadecimal number; <address> is a location number or a label.

Group Instruction What it does
Data movement LDM #n load the number n into ACC (immediate)
LDD <address> load the contents of the address into ACC (direct)
LDI <address> the address holds another address; load the contents of that one into ACC (indirect)
LDX <address> add IX to the address and load the contents of the result into ACC (indexed)
LDR #n load the number n into IX
MOV <register> copy ACC into the named register (IX)
STO <address> store the contents of ACC at the address
Input and output IN read a key press and put its ASCII code in ACC
OUT output the character whose ASCII code is in ACC
Arithmetic ADD <address> / ADD #n add the contents of the address, or the number, to ACC
SUB <address> / SUB #n subtract from ACC
INC <register> / DEC <register> add 1 to, or subtract 1 from, ACC or IX
Compare CMP <address> / CMP #n compare ACC with the contents of the address, or with n, and set the flag
CMI <address> compare ACC with the contents of the address held at the address (indirect)
Jump JMP <address> jump to the address unconditionally
JPE <address> / JPN <address> jump if the last compare was equal / not equal
Bit manipulation AND, OR, XOR with #n, Bn, &n or <address> bitwise operation on ACC
LSL #n / LSR #n shift ACC logically n places left or right
END end the program

The "assembly language instructions are grouped" question wants the group names, and an instruction from each: data movement, input and output, arithmetic, unconditional and conditional jumps, compare, and bit manipulation.

العربية

يقوم CPU فعلياً بتشغيل الرمز الآلي — أنماط البتات، محددة لمعمارية واحدة. لغة التجميع هي شكل مقروء، بتعليمة واحدة لكل تعليمة آلية، مكتوبة باستخدام أسماء رمزية مثل LDD، ADD، JMP. مجمع يترجمها إلى رمز آلي.

يقوم المترجم بترجمة الرموز الاختصارية من لغة assembly إلى أنماط بتات من كود الآلة
يحول المجمع الأسماء الرمزية إلى أنماط بتات الرمز الآلي

مجمع ثنائي المرور

يقوم مجمع ثنائي المرور بقراءة المصدر مرتين:

  • المرحلة 1 تبني جدول الرموز: كل مرة يظهر فيها عنوان فرعي (مثل LOOP:)، نسجل عنوانه؛ لم يتم إنتاج أي كود بعد.
  • المرحلة 2 تولد الكود: ترجم كل تعليمة، وعندما تشير إحداها إلى عنوان فرعي (مثل JMP LOOP)، ابحث عن عنوانه في جدول الرموز.

المراوئان يتعاملان مع الإشارات الأمامية (قفزة إلى علامة مُعرفة لاحقاً).

مثال محلول. طبق عملية المجمع ثنائي المرور على هذا البرنامج، حيث تُخزن أول تعليمة فيه في العنوان 100.

        LDD  COUNT
LOOP:   DEC  ACC
        CMP  #0
        JPN  LOOP
        END
COUNT:  5

تقرأ المرحلة 1 كل سطر، تحسب العنوان الذي سيحتله، وتسجل كل عناوين فرعية في جدول الرموز: LOOP = 101 (السطر DEC) وCOUNT = 105 (سطر البيانات). لا يتم إنتاج كود. تقرأ المرحلة 2 البرنامج مرة أخرى وترجم كل سطر إلى لغة الآلة، استبدال كل رمز بصيغة مختصرة برقمها الأوامر، وكل عنوان رمزي بالرقم من جدول الرموز: LDD COUNT يصبح أوامر لـ LDD مع عامل 105، وJPN LOOP يصبح أوامر لـ JPN مع عامل 101. كان بالإمكان حل القفز إلى LOOP في مرحلة واحدة، لكن القفز للأمام إلى عنوان فرعي لم يُرَ بعد لم يكن ممكناً، ولهذا يقوم المترجم بإجراء مرحلتين.

مجموعة تعليمات نموذجية

تستخدم كامبريدج مجموعة عامة صغيرة مطبوعة في جدول المرجع للورقة، مع مسجل واحد للاستخدام العام وهو المجمع (ACC)، ومسجل فهرسة (IX). المعامل المكتوب #n هو عدد عشري، Bn عدد ثنائي و&n عدد سداسي عشر؛ <address> هو رقم موقع أو علامة.

المجموعة التعليمة ماذا تفعل
نقل البيانات LDM #n تحميل الرقم n في ACC (فوري)
LDD <address> تحميل محتويات العنوان في ACC (مباشر)
LDI <address> يحتوي العنوان على عنوان آخر؛حميل محتويات ذلك العنوان في ACC (غير مباشر)
LDX <address> إضافة IX إلى العنوان وتحميل محتويات النتيجة في ACC (فهرسي)
LDR #n تحميل الرقم n في IX
MOV <register> نسخ ACC إلى المسجل المسمى (IX)
STO <address> تخزين محتويات ACC عند العنوان
الإدخال والإخراج IN قراءة ضغط مفتاح ووضع كود ASCII الخاص به في ACC
OUT إخراج الحرف الذي يكون كود ASCII الخاص به في ACC
حسابي ADD <address> / ADD #n إضافة محتويات العنوان، أو الرقم، إلى ACC
SUB <address> / SUB #n طرح من ACC
INC <register> / DEC <register> إضافة 1 إلى، أو طرح 1 من، ACC أو IX
مقارنة CMP <address> / CMP #n مقارنة ACC مع محتويات العنوان، أو مع n، وتعيين العلم
CMI <address> مقارنة ACC مع محتويات العنوان المحفوظ عند العنوان (غير مباشر)
قفز JMP <address> القفز إلى العنوان بشكل غير مشروط
JPE <address> / JPN <address> القفز إذا كان آخر مقارنة مساوياً / غير مساوٍ
معالجة البتات AND، OR، XOR مع #n، Bn، &n أو <address> عملية على مستوى البت في المسجل ACC
LSL #n / LSR #n إزاحة المنطقية لـACC بمقدار n خانة يساراً أو يميناً
END إنهاء البرنامج

سؤال "تجميع تعليمات لغة التجميع" يطلب أسماء المجموعات وتعليمة واحدة من كل مجموعة: نقل البيانات، الإدخال والإخراج، الحساب، القفز غير المشروط والمشروط، المقارنة، ومعالجة البتات.

Explore · ⁨استكشف⁩

How a two-pass assembler works · ⁨كيف يعمل مترجم التجميع ثنائي المرور⁩

Step through it. The assembler reads your code twice: pass 1 just finds where every label lives, so pass 2 can fill in the addresses — that is how a jump to a label defined later still works. · ⁨مرر الكود خطوة بخطوة. يقرأ المترجم الرمزي كودك مرتين: المرور 1 يبحث فقط عن مواقع كل العلامات المرجعية، لذا فإن المرور 2 يمكنه ملء العناوين — وهكذا يعمل القفز إلى علامة مرجعية مُعرَّفة لاحقًا.⁩

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
register/ˈredʒɪstə/ مسجل
control unit/kənˈtrəʊl ˈjuːnɪt/ وحدة التحكم
clock speed/klɒk spiːd/ سرعة الساعة
4.2

Addressing modes · ⁨أوضاع العنونة⁩

English

The addressing mode 寻址方式 (the modes of addressing) says how the CPU finds the operand:

  • immediate addressing 立即寻址 — the operand is the value in the instruction. LDM #10 loads 10.
  • direct addressing 直接寻址 — the instruction holds an address; the operand is the value there. LDD 200.
  • indirect addressing 间接寻址 — the instruction holds an address that holds another address, which is the data. LDI 200.
  • indexed addressing 变址寻址 — effective address is address + index register; used for arrays. LDX 100 with IR = 5 reads address 105.

(Relative addressing 相对寻址 gives the address as an offset from the PC — used for jumps.)

Worked example. Memory holds: location 200 = 250, location 250 = 99, location 105 = 7. The index register holds 5. What is in the accumulator after each of LDM #200, LDD 200, LDI 200 and LDX 100? Follow how far each mode has to look. LDM #200 is immediate - the operand is the number written in the instruction, so the accumulator holds 200. LDD 200 is direct - go to location 200 and take what is there: 250. LDI 200 is indirect - location 200 holds 250, which is another address, so go on to location 250: 99. LDX 100 is indexed - add the index register to the address, $100 + 5 = 105$, and read location 105: 7. Count the hops to keep them apart: immediate 0, direct 1, indirect 2, indexed 1 (once the index has been added).

العربية

وضع العنونة (أو أوضاع العنونة) يوضح كيف يجد المعالج operand:

  • العنونة الفورية — operand هو القيمة الموجودة في التعليمة. LDM #10 يحمل 10.
  • العنونة المباشرة — تحمل التعليمة عنواناً؛ والـoperand هي القيمة الموجودة هناك. LDD 200.
  • العنوبة غير المباشرة — تحمل التعليمة عنواناً يحتوي على عنوان آخر، وهو البيانات. LDI 200.
  • العنونة المؤشرية — العنوان الفعال هو address + index register؛ تستخدم للمصفوفات. LDX 100 مع IR = 5 يقرأ العنوان 105.

(العنونة النسبية تعطي العنوان كإزاحة عن PC — تستخدم للقفز.)

أربعة أوضاع عنوية تصل إلى operand الخاص بها. الفورية: LDM #10 يعطي 10 مباشرة. المباشرة: LDD 200 تقرأ موقع الذاكرة 200 (=42). غير المباشرة: LDI 200 تقرأ الموقع 200 (=250) ثم الموقع 250 (=99). المؤشرية: LDX 100 مع مسجل مؤشر 5 تقرأ الموقع 105 (=7)
كيف يصل كل وضع عنوي إلى operand الخاص به — الفوري، المباشر، غير المباشر والمؤشري

مثال محلول. الذاكرة تحتوي: الموقع 200 = 250، الموقع 250 = 99، الموقع 105 = 7. مسجل المؤشر يحتوي 5. ماذا يوجد في المسجل ACC بعد كل من LDM #200، LDD 200، LDI 200 و LDX 100؟ اتبع مدى البحث الذي يحتاجه كل وضع. LDM #200 هو فوري - operand هو الرقم المكتوب في التعليمة، لذا يحمل ACC 200. LDD 200 هو مباشر - اذهب إلى الموقع 200 وأخذ ما فيه: 250. LDI 200 هو غير مباشر - الموقع 200 يحتوي 250، وهو عنوان آخر، لذا استمر إلى الموقع 250: 99. LDX 100 هو مؤشري - أضف مسجل المؤشر إلى العنوان، $100 + 5 = 105$، واقرأ الموقع 105: 7. احسب القفزات لفصلها: فوري 0، مباشر 1، غير مباشر 2، مؤشري 1 (بعد إضافة المؤشر).

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
operand/ˈɒpərænd/ عامل
Index Register/ˈɪndeks ˈredʒɪstə/ مسجل الفهرس
indexed addressing/ˈɪndekst əˈdresɪŋ/ عنونة مؤشَّرة
general-purpose registers/ˈdʒenərəl ˈpɜːpəs ˈredʒɪstəz/ مسجلات متعددة الأغراض
register transfer/ˈredʒɪstə ˈtrænsfɜː/ انتقال المسجلات
control bus/kənˈtrəʊl bʌs/ حاجز التحكم
addressing mode/əˈdresɪŋ məʊd/ وضع العنونة
immediate addressing/ɪˈmiːdɪət əˈdresɪŋ/ عنونة مباشرة
direct addressing/daɪˈrekt əˈdresɪŋ/ عنونة فورية
indirect addressing/ɪndaɪˈrekt əˈdresɪŋ/ عنونة غير مباشرة
relative addressing/ˈrelətɪv əˈdresɪŋ/ عنونة نسبية
logical shift/ˈlɒdʒɪkl ʃɪft/ إزاحة منطقية
cyclic shift/ˈsaɪklɪk ʃɪft/ إزاحة دورية
4.2

Tracing an assembly program · ⁨تتبع برنامج تجميع⁩

English

To trace it: make a table with columns for the PC, ACC, index register, each variable and any flags. Step through the instructions, updating the table after each; follow branches when they change the PC; stop at END. A common pattern is a loop over an array using indexed addressing.

Worked example. Trace this program. Address 200 holds 5 and address 201 holds 0.

Write one row for each instruction executed, filling in only the columns that change:

Instruction ACC 200 201 Output
start 5 0
LDD 200 5
CMP #0
JPE 108 not taken
OUT character with code 5
DEC ACC 4
STO 200 4
LDD 201 0
JMP 100
LDD 200 4

and so on, until LDD 200 loads 0, the compare sets the equal flag, JPE 108 is taken and the program ends. Three things the examiner checks: a CMP changes no register, only a flag; a jump not taken still counts as executed; and OUT outputs a character, so it goes in the output column, not the ACC column. "State the effect of changing LDD 10 to LDM #10": the ACC would hold the number 10 instead of the contents of address 10.

العربية

لـتتبعه: قم بإنشاء جدول بأعمدة لـPC، ACC، مسجل المؤشر، كل متغير وأي علامات. مر عبر التعليمات، محدثاً الجدول بعد كل منها؛ اتبع الفروع عندما تغير PC؛ توقف عند END. نمط شائع هو حلقة تمر على مصفوفة باستخدام العنونة المؤشرية.

مثال محلول. تتبع هذا البرنامج. العنوان 200 يحتوي 5 والعنوان 201 يحتوي 0.

100   LDD  200
101   CMP  #0
102   JPE  108
103   OUT
104   DEC  ACC
105   STO  200
106   LDD  201
107   JMP  100
108   END

اكتب صف واحد لكل تعليمة يتم تنفيذها، مملئاً فقط الأعمدة التي تتغير:

التعليمة ACC 200 201 إخراج
بداية 5 0
LDD 200 5
CMP #0
JPE 108 لم تُتخذ
OUT حرف بأكواد 5
DEC ACC 4
STO 200 4
LDD 201 0
JMP 100
LDD 200 4

وهكذا، حتى LDD 200 يحمل 0، تضع المقارنة علامة المساواة، JPE 108 تُتخذ وينتهي البرنامج. ثلاثة things يفحصهم الممتحن: a CMP لا يغير أي مسجل، بل علامة فقط؛ قفز لم يُتخذ يُحسب كتنفيذ؛ و OUT يخرج حرفاً، لذا يوضع في عمود الإخراج، وليس عمود ACC. "حدد تأثير تغيير LDD 10 إلى LDM #10": سيحمل ACC الرقم 10 بدلاً من محتوى العنوان 10.

4.3

Binary shifts · ⁨إزاحات ثنائية⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding of and perform binary shifts Logical, arithmetic and cyclic Left shift, right shift
Show understanding of how bit manipulation can be used to monitor/control a device Carry out bit manipulation operations Test and set a bit (using bit masking)
Instruction Label | Opcode | Operand Explanation
AND #n / Bn / &n Bitwise AND operation of the contents of ACC with the operand
AND
Bitwise AND operation of the contents of ACC with the contents of
XOR #n / Bn / &n Bitwise XOR operation of the contents of ACC with the operand
XOR
Bitwise XOR operation of the contents of ACC with the contents of
OR #n / Bn / &n Bitwise OR operation of the contents of ACC with the operand
OR
Bitwise OR operation of the contents of ACC with the contents of
LSL #n Bits in ACC are shifted logically n places to the left. Zeros are introduced on the right hand end
LSR #n Bits in ACC are shifted logically n places to the right. Zeros are introduced on the left hand end
Labels an instruction
Gives a symbolic address
All questions will assume there is only one general purpose register available (Accumulator) ACC denotes Accumulator IX denotes Index Register
can be an absolute or symbolic address # denotes a denary number, e.g. #123 B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g. &4A
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
إظهار الفهم وأداء الإزاحة الثنائية المنطقية، الحسابية والدورانية إزاحة يسرى، إزاحة يمنى
إظهار الفهم لكيفية استخدام معالجة البتات لمراقبة/التحكم في جهاز إجراء عمليات معالجة البتات اختبار وتعيين بت (باستخدام قناع البتات)
تسمية التعليمات | كود العملية | المعامل شرح
AND #n / Bn / &n عملية AND منطقية لمحتويات المسجل التراكمي مع المعامل
AND
عملية AND منطقية لمحتويات المسجل التراكمي مع محتويات
XOR #n / Bn / &n عملية XOR منطقية لمحتويات المسجل التراكمي مع المعامل
XOR
عملية XOR منطقية لمحتويات المسجل التراكمي مع محتويات
OR #n / Bn / &n عملية OR منطقية لمحتويات المسجل التراكمي مع المعامل
OR
عملية OR المنطقية للمحتويات المسجلة في ACC مع محتويات
LSL #n يتم إزاحة البتات في المسجل التراكمي منطقياً بمقدار n خانات إلى اليسار. يتم إدخال أصفار في الطرف الأيمن
LSR #n يتم إزاحة البتات في المسجل التراكمي منطقياً بمقدار n خانات إلى اليمين. يتم إدخال أصفار في الطرف الأيسر
يُسمِّي تعليمة
يعطي عنواناً رمزياً
جميع الأسئلة تفترض وجود مسجل الأغراض العامة واحد فقط متاح (المسجل التراكمي) يشير ACC إلى المسجل التراكمي يشير IX إلى مسجل المؤشر
يمكن أن يكون عنواناً مطلقاً أو رمزياً يشير # إلى عدد عشري، مثال #123 يشير B إلى عدد ثنائي، مثال B01001010 يشير & إلى عدد سداسي عشر، مثال &4A

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

A logical shift 逻辑移位 moves all the bits left or right by some places, filling new positions with 0.

  • left shift by 1 (LSL #1) — bits move left, a 0 enters on the right; for an unsigned number this is × 2.
  • right shift by 1 (LSR #1) — bits move right, a 0 enters on the left; for an unsigned number this is integer ÷ 2.

Shifting by $n$ places multiplies or divides by $2^{n}$. Example: 00001011 (11) LSL #1 → 00010110 (22).

Bits shifted off the end are lost, so the multiplication is only correct while they were zeros. LSL #2 on the two's-complement integer 11001010 gives 00101000: the two 1s that fell off the left are gone, the sign bit has changed, and the result is no longer four times the original.

An arithmetic right shift keeps the sign bit so a negative signed number stays negative. A cyclic shift 循环移位 (rotate) feeds the bit that drops off one end back in at the other end, so no bits are lost.

"Show the result of an arithmetic right shift of 3 places on 10011110": copy the sign bit into each vacated place, 11110011. The same shift on 01011100 gives 00001011. A cyclic left shift of 1 on 10000110 gives 00001101: the leading 1 reappears on the right.

The difference between the two right shifts is a single bit. Take 11110000, which is 240 read as unsigned and $-16$ read as signed. LSR #1 brings in a 0 and gives 01111000 $= 120$, which is the correct half of 240. ASR #1 copies the sign bit instead and gives 11111000 $= -8$, which is the correct half of $-16$. Neither is wrong — each halves the value under one reading.

Bit manipulation for monitoring/control

Embedded devices often use one bit 位 of a register per signal (e.g. bit $n$ = LED $n$). Using a mask 掩码 — bit masking — you can:

  • set bit $n$: R = R OR a mask with bit $n$ set.
  • clear bit $n$: R = R AND a mask with bit $n$ clear and the rest set.
  • toggle bit $n$: R = R XOR a mask with bit $n$ set.
  • test bit $n$: R AND the mask, then check if the result is non-zero.

Bit manipulation is fast, uses little memory, and lets one byte hold up to 8 on/off states.

In the exam's instruction set these are AND, OR and XOR with a mask written as a denary, binary or hexadecimal operand. With the ACC holding 10101100:

Instruction Mask Result in ACC Effect
AND B00001111 00001111 00001100 keeps only the low four bits (clears the others)
OR #1 00000001 10101101 sets the least significant bit, leaving the rest unchanged
XOR &FF 11111111 01010011 inverts every bit
AND B00001000 then CMP #0 00001000 00001000 tests bit 3: the compare is not equal, so bit 3 was set
LSL #2 10110000 shifts left two places, losing the top two bits
LSR #3 00010101 shifts right three places, zeros entering on the left

"Write the instruction that sets the least significant bit to 1 and leaves the others unchanged": OR #1, or OR B00000001. To clear a bit use AND with a mask that has a 0 in that place and 1s elsewhere; to test a bit, AND with a mask that has a 1 only in that place, then compare the result with zero. In a monitoring device, one bit of a register per sensor lets a single AND check whether a particular sensor is on, and one OR switches an actuator's control bit on without disturbing the others.

العربية

الإزاحة المنطقية تحرك جميع البتات يساراً أو يميناً بمقدار بعض الخانات، ملء المواقع الجديدة بـ0.

  • إزاحة يسار بمقدار 1 (LSL #1) — تتحرك البتات يساراً، يدخل 0 من اليمين؛ للرقم غير الإشارةي هذا هو × 2.
  • إزاحة يمين بمقدار 1 (LSR #1) — تتحرك البتات يميناً، يدخل 0 من اليسار؛ للرقم غير الإشارةي هذا هو integer ÷ 2.

الإزاحة بمقدار $n$ خانات تضرب أو تقسم على $2^{n}$. مثال: 00001011 (11) LSL #1 → 00010110 (22).

البيتات المُزاحة من النهاية تُفقَد، لذا فإن عملية الضرب صحيحة فقط طالما كانت هذه البتات أصفاراً. عملية LSL #2 على عدد صحيح بتكامل الثمانيتين 11001010 تعطي 00101000: البتان 1 اللذان سقطا من اليسار ضيعا، وتغيرت بت الإشارة، ولم يعد الناتج أربعة أضعاف الأصل.

الإزاحة اليمنى الحسابية تحافظ على بت الإشارة ليظل العدد السالب الإشارة سالباً. الإزاحة الدائرية (دوران) تغذي البت الذي يسقط من أحد الطرفين مرة أخرى في الطرف الآخر، لذا لا تُفقد بتات.

"أظهر نتيجة إزاحة يمين حسابية بمقدار 3 خانات على 10011110": انسخ بت الإشارة في كل مكان شاغر، 11110011. نفس الإزاحة على 01011100 تعطي 00001011. إزاحة يسار دائرية بمقدار 1 على 10000110 تعطي 00001101: يظهر leading 1 مرة أخرى على اليمين.

ثلاثة إزاحات 8-بت: LSL #1 يحول 00001011 إلى 00010110 (ضرب في 2، يدخل 0 من اليمين); LSR #1 يحوله إلى 00000101 (قسمة صحيحة على 2، يدخل 0 من اليسار); ASR #1 يحول 10110100 إلى 11011010، بنسخ بت الإشارة
إزاحة يسار منطقية ($\times 2$)، إزاحة يمين منطقية ($\div 2$) وإزاحة يمين حسابية (تحافظ على بت الإشارة)

الفرق بين إزاحتي اليمين هو بت واحد. خذ 11110000، وهو 240 مقروءً كعدد غير إشارةي و$-16$ مقروءً كعدد إشارةي. LSR #1 يجلب 0 ويعطي 01111000 $= 120$، وهو النصف الصحيح من 240. ASR #1 ينسخ بت الإشارة ويعطي 11111000 $= -8$، وهو النصف الصحيح من $-16$. لا أحدهما خاطئ — كل منهما ينصف القيمة تحت قراءة واحدة.

البايت 11110000 مُزاح إلى اليمين مرتين: LSR يُدخل 0 من اليسار مما يعطي 01111000 وهي 120، بينما ASR ينسخ بت الإشارة فيعطي 11111000 وهو سالب 8؛ differs only in the bit that entered
إزاحة يمين منطقية وحسابية على نفس البايت: differs only in the bit that enters on the left

معالجة البتات للمراقبة/التحكم

الأجهزة المدمجة غالباً ما تستخدم بت واحد من المسجل لكل إشارة (مثلاً بت $n$ = LED $n$). باستخدام قناع — تخفيق البتات — يمكنك:

  • ضبط بت $n$: R = R OR قناعًا مع ضبط بت $n$.
  • إزالة بت $n$: R = R AND قناع ببت $n$ صفر والباقي مفعّل.
  • تبديل بت $n$: R = R XOR قناعًا مع ضبط بت $n$.
  • اختبار بت $n$: R AND القناع، ثم تحقق مما إذا كان النتيجة غير صفرية.
إخفاء البتات على البايت 01001000: ضبط بت 2 باستخدام OR 00000100 للحصول على 01001100؛ مسح بت 6 باستخدام AND 10111111 للحصول على 00001000؛ تبديل بت 3 باستخدام XOR 00001000 للحصول على 01000000
ضبط بت باستخدام OR، مسحه باستخدام AND، تبديله باستخدام XOR — كل منها يستخدم قناعًا

معالجة البتات سريعة، وتستهلك ذاكرة قليلة، وتسمح لبايت واحد باستيعاب ما يصل إلى 8 حالات تشغيل/إيقاف.

في مجموعة تعليمات الامتحان هذه هي AND، OR وXOR مع كتابة قناع كعامل عشري أو ثنائي أو سداسي عشر. مع احتواء ACC على 10101100:

التعليمات القناع النتيجة في ACC التأثير
AND B00001111 00001111 00001100 يحافظ فقط على أربع البتات السفلية (يمسح البتات الأخرى)
OR #1 00000001 10101101 يضبط أقل بت أهمية، تاركة الباقي دون تغيير
XOR &FF 11111111 01010011 يعكس كل بت
AND B00001000 ثم CMP #0 00001000 00001000 يختبر بت 3: المقارنة غير متساوية، لذا كان بت 3 مضبوطًا
LSL #2 10110000 إزاحة لليسار مكانين، فقدان أعلى بتين
LSR #3 00010101 يزيح يميناً بثلاث أماكن، أصفار تدخل من اليسار

"اكتب التعليمة التي تجعل أقل بت معنوية يساوي 1 وتترك الباقي دون تغيير": OR #1، أو OR B00000001. لإزالة بت استخدم AND مع قناع يحتوي على 0 في ذلك المكان و1s في الأماكن الأخرى؛ لاختبار بت، AND مع قناع يحتوي على 1 فقط في ذلك المكان، ثم قارن النتيجة بالصفر. في جهاز مراقبة، يسمح بت واحد من المسجل لكل مستشعر لأحد AND بالتحقق من تشغيل مستشعر معين، ويُمكّن OR واحد تشغيل بت التحكم في المؤثر دون الإضرار بالآخرين.

Explore · ⁨استكشف⁩

Shift and mask the bits of a byte · ⁨ازح وقلِّص بتات البايت⁩

Pick an operator and watch each result bit. A left shift (<<) moves every bit up one place (×2); a right shift (>>) moves them down (÷2); AND with a mask clears the bits you don't want. · ⁨اختر عاملاً وعقب كل بت ناتج. الإزاحة اليسرى (<<) moves every bit up one place (×2); a right shift (>>) تنقلها لأسفل (÷2)؛ والـ AND مع قناع يُفرغ البتات التي لا تريدها.⁩

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
bit/bɪt/ بت
mask/mæsk/ قناع
4.3

Definitions the examiner accepts · ⁨التعريفات التي يقبلها المصحح⁩

English

A definition question is marked against fixed wording. Learn these exactly, and give one answer only.

Term Definition
stored program concept the program instructions and the data are both held in main memory, and instructions are fetched and executed one at a time
register a small, very fast storage location inside the processor with a specific purpose
Program Counter the register holding the address of the next instruction to be fetched
Memory Address Register the register holding the address of the memory location being read from or written to
Memory Data Register the register holding the data or instruction just read from, or about to be written to, memory
Current Instruction Register the register holding the instruction currently being decoded and executed
Accumulator the general-purpose register holding the result of the last arithmetic or logic operation
cache memory small, fast memory close to the processor holding frequently used instructions and data
interrupt a signal from a device or program that causes the processor to pause the current task and run an interrupt service routine
assembly language a low-level language in which each mnemonic instruction corresponds to one machine-code instruction
immediate addressing the operand is the value written in the instruction
direct addressing the operand is the contents of the address written in the instruction
indirect addressing the address in the instruction holds the address of the operand
indexed addressing the operand's address is the address in the instruction plus the contents of the index register
relative addressing the operand's address is given as an offset from the address of the current instruction
logical shift every bit moves the given number of places and zeros fill the vacated places
العربية

تُصنّف أسئلة التعريف بناءً على صياغة ثابتة. احفظ هذه التعريفات بدقة، وقدم إجابة واحدة فقط.

مصطلح تعريف
مفهوم البرنامج المخزن يتم الاحتفاظ بتعليمات البرنامج والبيانات معاً في الذاكرة الرئيسية، ويتم جلب التعليمات وتنفيذها واحدة تلو الأخرى
المسجلات موقع تخزين صغير وسريع جداً داخل المعالج له غرض محدد
عداد البرنامج المسجل الذي يحمل عنوان التعليمة التالية التي سيتم جلبها
مسجل عنوان الذاكرة المسجل الذي يحمل عنوان موقع الذاكرة الذي يتم القراءة منه أو الكتابة إليه
مسجل بيانات الذاكرة المسجل الذي يحمل البيانات أو التعليمة التي تم读取ها للتو من الذاكرة، أو التي سيتم كتابتها إليها
مسجل التعليمة الحالية المسجل الذي يحمل التعليمة التي يتم فك تشفيرها وتنفيذها حالياً
المجمع المسجل متعدد الأغراض الذي يحمل نتيجة آخر عملية حسابية أو منطقية
ذاكرة الكاش ذاكرة صغيرة وسريعة قريبة من المعالج تحتفظ بالتعليمات والبيانات المستخدمة بشكل متكرر
المقاطعة إشارة من جهاز أو برنامج تتسبب في إيقاف المعالج للمهمة الحالية وتشغيل روتين خدمة المقاطعة
لغة التجميع لغة منخفضة المستوى حيث يقابل كل دليل mnemonic تعليمة واحدة من تعليمات الآلة
العنونة الفورية العامل هو القيمة المكتوبة في التعليمة
العنونة المباشرة العامل هو محتويات العنوان المكتوب في التعليمة
العنونة غير المباشرة العنوان في التعليمة يحمل عنوان العامل
العنونة الفهرسية عنوان العامل هو العنوان في التعليمة زائد محتويات مسجل الفهرس
العنونة النسبية عنوان العامل معطى كإزاحة من عنوان التعليمة الحالية
الإزاحة المنطقية يتحرك كل بت عدد Places المعطى وتعبئ الأصفار الـ Places الشاغرة
4.3

Exam tips · ⁨نصائح للامتحان⁩

English
  • Learn the fetch-execute cycle in register-transfer terms (PC, MAR, MDR, CIR, ACC) and what increments the PC.
  • Name each register's job; the address bus is one-way, the data bus is two-way.
  • Distinguish the addressing modes (immediate, direct, indirect, indexed) — a frequent question.
  • Explain how clock speed, number of cores, cache size and word length affect performance.
  • For a binary shift, state whether it is logical or arithmetic; a left shift multiplies by 2, a right shift divides by 2.

Common mistakes

  • Saying the PC holds the current instruction, or the MDR holds an address. The PC holds the address of the next instruction; the MDR holds data or an instruction, never an address.
  • Leaving the increment of the PC out of the fetch, or putting it after the execute. It happens as soon as the address has been copied to the MAR.
  • Reading LDD 10 as "load 10". LDD 10 loads the contents of address 10; LDM #10 loads the number 10.
  • Putting a value in the ACC column for CMP or OUT. A compare sets a flag only; an output goes to the output column.
  • Saying an interrupt is handled "immediately". The processor finishes the current instruction and checks for interrupts at the end of the cycle.
  • Using a logical right shift on a negative two's-complement number. Only an arithmetic shift keeps the sign bit.
العربية
  • تعلم دورة الجلب والتنفيذ بمصطلحات نقل المسجلات (PC, MAR, MDR, CIR, ACC) وما يزيد PC.
  • سمّ عمل كل مسجل؛ ناقل العناوين أحادي الاتجاه، ناقل البيانات ثنائي الاتجاه.
  • ميز بين أوضاع العنونة (الفورية، المباشرة، غير المباشرة، الفهرسية) — سؤال شائع.
  • اشرح كيف تؤثر سرعة الساعة، عدد النواة، حجم الكاش وطول الكلمة على الأداء.
  • بالنسبة لـ الإزاحة الثنائية، حدد ما إذا كانت منطقية أو حسابية؛ الإزاحة اليسرى تضرب في 2، والإزاحة اليمنى تقسم على 2.

أخطاء شائعة

  • قول أن PC يحمل التعليمة الحالية، أو أن MDR يحمل عنواناً. PC يحمل عنوان التعليمة التالية؛ MDR يحمل بيانات أو تعليمة، لا عنوان أبداً.
  • ترك زيادة PC خارج الجلب، أو وضعها بعد التنفيذ. يحدث بمجرد نسخ العنوان إلى MAR.
  • قراءة LDD 10 على أنها "حمل 10". LDD 10 يحمل محتويات العنوان 10؛ LDM #10 يحمل الرقم 10.
  • وضع قيمة في عمود ACC لـ CMP أو OUT. المقارنة تضع علامة فقط؛ الإخراج يذهب إلى عمود الإخراج.
  • قول أن المقاطعة تُعالج "فوراً". ينهي المعالج التعليمة الحالية ويتحقق من المقاطعات في نهاية الدورة.
  • استخدام إزاحة يمنية منطقية على رقم مكمل اثنين سالب. فقط الإزاحة الحسابية تحافظ على بت الإشارة.

Interactive lessons on this topic · ⁨دروس تفاعلية حول هذا الموضوع⁩

Work through it step by step, with instant-check exercises. · ⁨ا-working عليه خطوة بخطوة، مع تمارين تحقق فوري.⁩

Past Papers · ⁨أوراق الامتحانات السابقة⁩

More topics in A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩ · ⁨المزيد من المواضيع في A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩⁩

Log in or create account · ⁨تسجيل الدخول أو إنشاء حساب⁩

IGCSE, A-Level & AP