Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Processor Fundamentals · ⁨พื้นฐานของโปรเซสเซอร์⁩

A-Level Computer Science · ⁨Computer Science A-Level⁩ · Topic 4 · ⁨หัวข้อ 4⁩

Video lesson for this topic · ⁨บทเรียนวิดีโอสำหรับหัวข้อนี้⁩ Open the video page · ⁨เปิดหน้าวิดีโอ⁩
21:32

สถาปัตยกรรม Von Neumann

ตลอดประวัติศาสตร์ส่วนใหญ่ เครื่องจักรทำงานเพียงอย่างหนึ่ง กระดุมทอผ้า คำนวณบวก เพื่อทำให้มันทำอะไรใหม่ คุณต้องสร้างมันใหม่ จากนั้นก็มาถึงสิ่งที่ดูเรียบง่ายแต่ลวงตา…

English narration · English + 中文 subtitles burned in · ⁨การบรรยายภาษาอังกฤษ · คำบรรยายภาษาอังกฤษ + 中文 ลอยตัวบนภาพ⁩

4.1

Von Neumann architecture · ⁨สถาปัตยกรรม Von Neumann⁩

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
ไทย
ผู้เข้าสอบควรสามารถ: หมายเหตุและคำแนะนำ
แสดงความเข้าใจในโมเดลพื้นฐานของ Von Neumann สำหรับระบบคอมพิวเตอร์และแนวคิด โปรแกรมที่เก็บไว้
แสดงความเข้าใจถึงวัตถุประสงค์และบทบาทของ รีจิสเตอร์ (registers) รวมถึงความแตกต่างระหว่าง รีจิสเตอร์ทั่วไป และ รีจิสเตอร์เฉพาะทาง รีจิสเตอร์เฉพาะทาง ได้แก่: • Program Counter (PC) • Memory Data Register (MDR) • Memory Address Register (MAR) • Accumulator (ACC) • Index Register (IX) • Current Instruction Register (CIR) • Status Register
แสดงความเข้าใจถึงวัตถุประสงค์และบทบาทของ Arithmetic and Logic Unit (ALU), Control Unit (CU) และ system clock, Immediate Access Store (IAS)
แสดงความเข้าใจ نحوه ILoggerข้อมูลระหว่างส่วนประกอบต่างๆ ของระบบคอมพิวเตอร์โดยใช้ address bus, data bus และ control bus
แสดงความเข้าใจว่าปัจจัยใดมีผลต่อประสิทธิภาพของระบบคอมพิวเตอร์ รวมถึง: • ประเภทและจำนวน cores ของโปรเซสเซอร์ • bus width • clock speed • cache memory
เข้าใจว่าพอร์ตต่างๆ ให้การเชื่อมต่ออุปกรณ์ต่อพ่วงอย่างไร รวมถึงการเชื่อมต่อกับ: • Universal Serial Bus (USB) • High Definition Multimedia Interface (HDMI) • Video Graphics Array (VGA)
อธิบายขั้นตอนของรอบ Fetch-Execute (F-E) อธิบายและใช้ notation 'register transfer' เพื่ออธิบายรอบ F-E
แสดงความเข้าใจถึงวัตถุประสงค์ของ Interrupts รวมถึง: • สาเหตุที่เป็นไปได้ของ Interrupts • การประยุกต์ใช้ Interrupts • การใช้ Interrupt Service Routine (ISR) • เวลาที่ Detect Interrupts ระหว่างรอบ fetch-execute • วิธีการจัดการ Interrupts

Source: Cambridge International syllabus · ⁨แหล่งที่มา: หลักสูตร Cambridge International⁩

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.

ไทย
วัฏจักร fetching-decoding-executing

สถาปัตยกรรม Von Neumann· รองรับคอมพิวเตอร์ทั่วไปเกือบทุกเครื่อง:

  • หน่วยความจำเดียว — ** Immediate Access Store** (IAS) — เก็บทั้ง คำสั่งโปรแกรม และ ข้อมูล (แนวคิด program ที่จัดเก็บไว้).
  • โปรเซสเซอร์ (CPU) ดึงคำสั่งจากหน่วยความจำและรันทีละตัว.
  • คำสั่งรัน ตามลำดับ เว้นแต่ branch จะเปลี่ยนการไหล.

แนวคิด stored-program คือสิ่งที่ทำให้คอมพิวเตอร์มีความยืดหยุ่น: เปลี่ยนโปรแกรมก็เปลี่ยนสิ่งที่มันทำได้ โดยไม่ต้องเดินสายใหม่.

Explore · ⁨สำรวจ⁩

Tap the parts of a Von Neumann computer · ⁨แตะส่วนประกอบของคอมพิวเตอร์ Von Neumann⁩

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. · ⁨สำรวจแต่ละบล็อก CPU (หน่วยควบคุม, ALU, รีจิสเตอร์) สื่อสารกับหน่วยความจำหลักเพียงแห่งเดียวผ่านบัส — และหน่วยความจำร่วมกันนี้สำหรับคำสั่ง AND ข้อมูลคือแนวคิดของ Von Neumann⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
Immediate Access Store/ɪˈmiːdɪət ˈækses stɔː/ หน่วยเก็บเข้าถึงทันที
stored program/stɔːd ˈprəʊɡræm/ โปรแกรมจัดเก็บ
RAM/ræm/ RAM
4.1

The CPU's main parts · ⁨ส่วนประกอบหลักของ CPU⁩

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 บนพื้นหลังสีขาว, สี่เหลี่ยมแบนปกคลุมด้วยตารางของแผ่นสัมผัสสีทองขนาดเล็กนับร้อยที่กดลงบนซ็อกเก็ตบนเมนบอร์ด
CPU สมัยใหม่: โปรเซสเซอร์ทั้งหมดคือชิปเล็กชิ้นหนึ่ง (เห็นจากด้านล่าง แสดงจุดสัมผัส)
ซ็อกเก็ตซีพียูสี่เหลี่ยมบนเมนบอร์ด, มีตารางหมุดเล็กๆ จำนวนมากและคันโยกล็อคโลหะ, ล้อมรอบด้วยเส้นวงจรไฟฟ้า
ซ็อกเก็ต CPU ที่ตรงกับบนเมนบอร์ด: จุดสัมผัสของชิกดันลงบนหมุดเหล่านี้

หน่วยคำนวณและตรรกะ (ALU)

ALU ทำ arithmetic (บวก, ลบ, …) และ logic (AND, OR, เปรียบเทียบ) รับ operands จาก registers และใส่ผลลัพธ์กลับเข้าไปใน register.

Control Unit (CU)

control unit decode แต่ละคำสั่งและส่ง control signals เพื่อดำเนินการ — เปิด data paths, บอก ALU ว่าต้องทำอะไร, และควบคุมการอ่าน/เขียนหน่วยความจำ.

ระบบนาฬิกา

นาฬิกาส่ง脈 steady ของ pulses ที่ทำให้ CPU ทำงานประสานกัน คำสั่งแต่ละตัวใช้เวลา cycles จำนวนคงที่ และ clock speed (เช่น 3.8 GHz) เป็นปัจจัยหนึ่งในประสิทธิภาพ.

"อธิบายวิธี CU และระบบนาฬิกาทำงานร่วมกัน": นาฬิกาปล่อย pulses ที่ความถี่คงที่; control unit ใช้แต่ละ pulse để推进 fetch-execute cycle ไปข้างหน้าหนึ่งขั้นตอน, ส่ง control signals ตามจังหวะกับ pulses, ทำให้ทุกส่วนของโปรเซสเซอร์เปลี่ยนสถานะพร้อมกัน นาฬิกาที่เร็วขึ้นหมายถึงขั้นตอนมากขึ้นต่อวินาที จนถึงจุดที่วงจรไม่สามารถ settle ระหว่าง pulses ได้

Registers

Registers เป็นที่เก็บขนาดเล็กมากและเร็วภายใน CPU special purpose registers แต่ละตัวมีหน้าที่ตายตัวในวัฏจักร:

  • Program Counter (PC) — ที่อยู่ของ คำสั่งถัดไป.
  • Memory Address Register (MAR) — ที่อยู่ที่กำลังอ่านหรือเขียน.
  • Memory Data Register (MDR) — ข้อมูลที่กำลังส่งเข้าหรือออกจากหน่วยความจำ.
  • Current Instruction Register (CIR) — คำสั่งที่กำลัง decode.
  • Accumulator (ACC) — ค่าที่ ALU กำลังประมวลผล.
  • สตาตัสเรจิสเตอร์ — เก็บ เฟล็ก (carry, zero, negative, overflow) ที่ใช้สำหรับการเบี่ยงเบนเส้นทาง Each flag เป็น 1 บิต ตั้งค่าหรือลบโดย ALU หลังการดำเนินการ: เฟล็ก zero หลังการเปรียบเทียบที่ตรงกัน, เฟล็ก carry เมื่อผลบวกเกินความจุของเรจิสเตอร์, เฟล็ก negative เมื่อผลลัพธ์เป็นลบ การกระโดดตามเงื่อนไขอ่านค่าเฟล็กเพื่อตัดสินใจว่าจะเบี่ยงเบนหรือไม่, และเฟล็ก overflow สามารถส่งสัญญาณขัดจังหวะได้
  • Index Register — offset บวกเข้ากับที่อยู่ในการ addressing แบบ index; การ increment ทำให้วนผ่าน array ตัวละหนึ่ง.

คำถาม "เติมตารางที่อธิบายบทบาทของแต่ละ register" ต้องการประโยคที่แม่นยำหนึ่งประโยคต่อregister ใน Terms เหล่านี้: PC เก็บที่อยู่ของคำสั่งถัดไปที่จะดึง; MAR เก็บที่อยู่ของตำแหน่งที่กำลังอ่านหรือเขียน; MDR เก็บข้อมูลหรือคำสั่งที่เพิ่งอ่านจากหรือกำลังจะเขียนไปยังตำแหน่งนั้น; CIR เก็บคำสั่งที่กำลัง decode และ run อยู่; ACC เก็บผลลัพธ์ของการดำเนินการ arithmetic หรือ logic ครั้งล่าสุด.

รีจิสเตอร์อเนกประสงค์ ใช้โดยโปรแกรมเมอร์สำหรับค่าชั่วคราวระหว่างการคำนวณ การถ่ายโอนข้อมูลระหว่างรีจิสเตอร์และหน่วยความจำเขียนในรูปสัญลักษณ์ register transfer — เช่น MAR ← [PC] ("คัดลอกเนื้อหาของ PC ลงใน MAR").

แผนภาพบล็อกของ CPU Von Neumann แสดง PC, MAR, MDR, CIR, ACC, รีจิสเตอร์สถานะ, หน่วยควบคุม, ALU และนาฬิการะบบ เชื่อมต่อกับหน่วยความจำหลักและอินพุต/เอาต์พุตผ่านบัสที่อยู่ ข้อมูล และควบคุม
CPUVon Neumann: รีจิสเตอร์, หน่วยควบคุม และ ALU เชื่อมต่อกันด้วยบัส
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
Von Neumann architecture/vɒn ˈnɔɪmən ˈɑːkɪtektʃə/ สถาปัตยกรรม Von Neumann
ALU/ˌeɪ el ˈjuː/ ALU
operand/ˈɒpərænd/ operand
register/ˈredʒɪstə/ รีจิสเตอร์ (register)
control unit/kənˈtrəʊl ˈjuːnɪt/ หน่วยควบคุม
clock speed/klɒk spiːd/ ความเร็ว clock
fetch-execute cycle/fetʃ ˈeksɪkjuːt ˈsaɪkl/ fetch-execute cycle
special purpose registers/ˈspeʃl ˈpɜːpəs ˈredʒɪstəz/ รีจิสเตอร์เฉพาะ
Program Counter/ˈprəʊɡræm ˈkaʊntə/ Program Counter
Memory Address Register/ˈmeməri əˈdres ˈredʒɪstə/ Memory Address Register
Memory Data Register/ˈmeməri ˈdeɪtə ˈredʒɪstə/ Memory Data Register
Current Instruction Register/ˈkʌrənt ɪnˈstrʌkʃn ˈredʒɪstə/ Current Instruction Register
accumulator/əˈkjuːmjʊleɪtə/ _accumulator
Status Register/ˈsteɪtəs ˈredʒɪstə/ Status Register
Index Register/ˈɪndeks ˈredʒɪstə/ Index Register
register transfer/ˈredʒɪstə ˈtrænsfɜː/ register transfer
control bus/kənˈtrəʊl bʌs/ control bus
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 → หน่วยความจำ).
  • บัสข้อมูล — ส่งข้อมูล เป็นสองทาง.
  • บัสควบคุม — ส่งสัญญาณควบคุม (อ่าน, เขียน, Interrupt) เป็นสองทาง.

บัสที่อยู่ขนาด $n$ บิต สามารถเข้าถึงตำแหน่งหน่วยความจำได้ $2^{n}$ ตำแหน่ง ความกว้างของบัสข้อมูลกำหนดจำนวนบิตที่ถ่ายโอนต่อการเข้าถึงหนึ่งครั้ง (มักเท่ากับขนาดคำ)

CPU, หน่วยความจำ และอินพุต/เอาต์พุต แต่ละส่วนเชื่อมต่อกับบัสที่อยู่ (ทางเดียว), บัสข้อมูล และบัสควบคุม ภายในระบบบัส
ระบบบัสสามชนิดเชื่อมต่อ CPU, หน่วยความจำ และอินพุต/เอาต์พุตเข้าด้วยกัน
เมนบอร์ดมองจากด้านบน: ซ็อกเก็ต CPU, ช่องใส่หน่วยความจำ และช่องขยาย เชื่อมต่อกันด้วยเส้นทางพิมพ์ที่หนาแน่น
เมนบอร์ด: CPU, หน่วยความจำ และ I/O ทั้งหมดอยู่บนชุดบัสเดียวกัน — คือเส้นทางการพิมพ์ที่วิ่งระหว่างองค์ประกอบเหล่านั้น
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
interrupt/ˈɪntərʌpt/ interrupt
buses/ˈbʌsɪz/ บัส
address bus/əˈdres bʌs/ address bus
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.

ไทย
  • ความเร็วรอบ (clock speed) — จำนวนรอบต่อวินาทีมากขึ้น
  • จำนวนคอร์ — CPU แบบมัลติคอร์สามารถรันหลายเธรดพร้อมกันได้
  • ขนาดคำ (word size) — CPU 64-บิต จัดการข้อมูลเป็นก้อนขนาด 64 บิตต่อรอบ และเข้าถึงหน่วยความจำได้มากกว่า CPU 32-บิตอย่างมาก
  • ปริมาณ RAM — RAM มากขึ้นเก็บชุดงาน working set ได้มากขึ้น; หากน้อยเกินไปจะทำให้ OS ต้องทำ page ไปยังดิสก์
  • ขนาดหน่วยความจำแคช — แคชมากลดเวลาเข้าถึงหน่วยความจำเฉลี่ยลง
  • ประเภทการจัดเก็บข้อมูลรอง — SSD โหลดโปรแกรมได้เร็วกว่า HDD มาก
  • ความกว้างและความเร็วของบัส — บัสที่กว้างหรือเร็วขึ้นช่วยส่งข้อมูลได้รวดเร็วขึ้น

จับคู่สเปกกับภาระงาน: Quad-core ดีกว่า Dual-core ในงานแบบขนาน แต่ความเร็วต่อคอร์ที่สูงกว่าชนะในงาน single-threaded

แต่ละปัจจัยเป็นคำตอบคะแนน 2 คะแนน พร้อมเหตุผลประกอบ:

  • คอร์มากขึ้น: แต่ละคอร์สามารถดึงและดำเนินการคำสั่งของตัวเองได้พร้อมกัน ทำให้หลายโปรแกรม หรือเธรดของโปรแกรมหนึ่ง ทำงานแบบขนานได้ แต่ต้องเขียนโปรแกรมให้รองรับการใช้หลายคอร์ ดังนั้นการเพิ่มคอร์เป็นสองเท่าไม่ทำให้ความเร็วเพิ่มขึ้นสองเท่าเสมอไป
  • ความเร็วรอบสูงขึ้น: มีรอบ fetch-execute ต่อวินาทีมากขึ้น จึงประมวลผลคำสั่งได้มากขึ้นต่อวินาที; ข้อจำกัดคือความร้อนที่เกิดขึ้น
  • บัสกว้างขึ้น: บัสข้อมูลที่กว้างขึ้นส่งข้อมูลได้มากกว่าต่อ一次การถ่ายโอน จึงใช้จำนวนการถ่ายโอนน้อยกว่าเพื่อส่งข้อมูลเท่าเดิม; บัสที่อยู่ที่กว้างขึ้นเข้าถึงตำแหน่งหน่วยความจำได้มากขึ้น
  • หน่วยความจำแคช: เป็นหน่วยความจำขนาดเล็กแต่เร็ว ที่อยู่ในหรือ毗邻 processor เก็บคำสั่งและข้อมูลที่ใช้งานล่าสุดหรือบ่อยที่สุด การอ่านจากแคชเร็วกว่า RAM มาก ทำให้โปรเซสเซอร์ใช้เวลารอให้น้อยลง

"อธิบายว่าทำไมคอมพิวเตอร์รุ่นใหม่จึงทำงานได้ดีขึ้น" ตอบด้วยการเปรียบเทียบสเปกทั้งสองแบบบรรทัดต่อบรรทัด: ความเร็วรอบสูงกว่าประมวลผลคำสั่งได้มากขึ้นต่อวินาที, คอร์越多รันงานได้พร้อมกันมากขึ้น, แคชมากขึ้นหมายถึงการเข้าถึง RAM ช้าลงน้อยลง, และ RAM มากขึ้นหมายถึงการถ่ายโอนไปยังดิสก์น้อยลง

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
processor/ˈprəʊsesə/ หน่วยประมวลผล
arithmetic and logic unit/ˌærɪθˈmetɪk ənd ˈlɒdʒɪk ˈjuːnɪt/ หน่วยคำนวณและตรรกะ
word size/wɜːd saɪz/ ขนาดคำ
number of cores/ˈnʌmbə ɒv kɔːz/ จำนวน cores
cores/kɔːz/ คอร์
amount of RAM/əˈmaʊnt ɒv 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/ อุปกรณ์ต่อพ่วง
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 (Universal Serial Bus) — อเนกประสงค์ (คีย์บอร์ด, ไดร์ฟ, โทรศัพท์)
  • HDMI (High Definition Multimedia Interface) — วิดีโอและเสียงดิจิทัลไปยังหน้าจอ
  • VGA (Video Graphics Array) — สัญญาณวิดีโอแอนะล็อกเก่าไปยังจอภาพ
  • Ethernet (RJ-45) — LAN แบบมีสาย. จacks เสียง — หูฟัง/ไมโครโฟน

พอร์ตต่างชนิดใช้สัญญาณต่างกัน ดังนั้นสาย HDMI จะเสียบไม่ได้กับซ็อกเก็ต USB USB-C มีความพิเศษในการรองรับวิดีโอ ข้อมูล และพลังงานในสายเดียว

"อธิบายว่าคอมพิวเตอร์เชื่อมต่อกับจอภาพผ่าน HDMIได้อย่างไร": พอร์ต HDMI ส่งวิดีโอและเสียงเป็นสัญญาณดิจิทัลรวมกันผ่านสายเดียว ไม่ต้องแปลงเป็นแอนะล็อก ภาพจึงไม่เสื่อมคุณภาพ สายรองรับความละเอียดสูง และพอร์ตบนจอภาพจะถอดรหัสสัญญาณเอง อุปกรณ์ USB เป็นแบบ plug-and-play: เมื่อเสียบเข้าแล้ว คอมพิวเตอร์จะตรวจจับ ระบุชื่อ โหลดไดรเวอร์ที่ต้องการ และอาจจ่ายไฟให้โดยอัตโนมัติโดยไม่ต้องรีสตาร์ท

4.1

Fetch-Execute cycle · ⁨รอบ fetch-execute⁩

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.

ไทย

CPU ทำซ้ำ รอบ fetch-execute — รันหนึ่งครั้งต่อคำสั่งเครื่องหนึ่ง

Fetch

  1. ที่อยู่ของ PC ถูกคัดลอกไปยัง MAR
  2. PC ถูก increment เพื่อชี้ไปที่คำสั่งถัดไป
  3. สัญญาณ read ส่งผ่านบัสควบคุม
  4. หน่วยความจำวางคำสั่งลงบนบัสข้อมูล
  5. คัดลอกเข้าไปใน MDR จากนั้นเข้าสู่ CIR

ข้อสอบถามขั้นตอนเหล่านี้ในรูปแบบ register transfer notation โดยที่ [X] หมายถึงเนื้อหาของรีจิสเตอร์ X และ [[MAR]] หมายถึงเนื้อหาของตำแหน่งหน่วยความจำwhose address อยู่ใน 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 จะถูก increment ทันทีหลังจากที่อยู่ของมันถูกคัดลอก เพื่อให้การ jump ที่เกิดขึ้นในภายหลังสามารถแทนที่ค่า PC นั้นได้ ระหว่างการ execute สัญลักษณ์เดียวกันนี้จะใช้อธิบายแต่ละคำสั่ง; สำหรับ LDD 200 ตัวอย่างเช่น MAR ← 200, MDR ← [[MAR]], ACC ← [MDR]

การถ่ายโอนรีจิสเตอร์ในรอบ fetch ตามลำดับ: 1 ที่อยู่ของ PC ไปยัง MAR; 2 MAR ส่งที่อยู่ไปยังหน่วยความจำ; 3 คำสั่งกลับมายัง MDR; 4 MDR คัดลอกไปยัง CIR; ขณะเดียวกันนั้น PC ถูก increment
การถ่ายโอนรีจิสเตอร์ในรอบ fetch: PC → MAR → หน่วยความจำ → MDR → CIR โดยมีการ increment PC

Decode

CU ตีความคำสั่งใน CIR — ว่าเป็นการดำเนินการใด และใช้ operand หรือที่อยู่ข้อมูลใด

การดำเนินการ (Execute)

CU ดำเนินการตามนั้น: การคำนวณทางคณิตศาสตร์/ตรรกะจะถูกส่งไปยัง ALU (ผลลัพธ์ไป ACC); การโหลด/จัดเก็บจะย้ายข้อมูลระหว่างหน่วยความจำและรีจิสเตอร์; การกระโดดจะเปลี่ยนค่า PC จากนั้นรอบการทำงานจะวนซ้ำอีกครั้ง

แผนภาพวงจร fetching-execution จาก START: ขั้นตอน fetch (PC ไป MAR, เพิ่มค่า PC, สัญญาณอ่าน, หน่วยความจำไปยัง data bus ไป MDR ไป CIR), ขั้นตอน decode, ขั้นตอน execute, จากนั้นตรวจสอบ interrupt แล้ววนกลับไปที่ START
วงจร fetching-execute พร้อมการตรวจสอบ interrupt ทุกครั้ง
Explore · ⁨สำรวจ⁩

The fetch-execute cycle · ⁨รอบ fetch-execute⁩

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. · ⁨แตะวนรอบที่ CPU ทำซ้ำหลายพันล้านครั้งต่อวินาที ดูว่า fetch ใช้รีจิสเตอร์ PC/MAR/MDR/CIR อย่างไร แล้ว decode และ execute ทำงานกับสิ่งที่ถูกดึงมา⁩

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. · ⁨逐步演示CPU如何运行一条指令——从内存中 fetch,decode,然后 execute,周而复始。⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
data bus/ˈdeɪtə bʌs/ data bus
register transfer notation/ˈredʒɪstə ˈtrænsfɜː nəʊˈteɪʃn/ Programming Transfer Notation
interrupt service routine/ˈɪntərʌpt ˈsɜːvɪs ruːˈtiːn/ Interrupt Service Routine
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.

ไทย

Interrupt คือสัญญาณที่ หยุด วงจรปกติชั่วคราว เพื่อให้ CPU สามารถจัดการกับเหตุการณ์เร่งด่วนได้ (เช่น การกดคีย์,数据包 arrives, ความผิดปกติของฮาร์ดแวร์, การหารด้วยศูนย์, ตัวจับเวลาของ OS)

การจัดการหนึ่งครั้ง:

  1. เสร็จสิ้นคำสั่งปัจจุบันให้เรียบร้อย
  2. บันทึกสถานะ (PC และรีจิสเตอร์)
  3. โหลดที่อยู่ของ โปรแกรมบริการ interrupt (ISR) ลงใน PC และรันมัน
  4. ISR จัดการเหตุการณ์นั้น
  5. คืนค่า สถานะที่บันทึกไว้แล้วดำเนินต่อ

Interrupt ทำให้ระบบตอบสนองได้อย่างรวดเร็วโดยไม่ต้องให้ CPU ตรวจสอบอุปกรณ์ตลอดเวลา และเป็นกลไกที่ OS ใช้สำหรับ multitasking

"อธิบายว่า interrupt จากอุปกรณ์อินพุตถูกตรวจจับและจัดการอย่างไรในวงจร F-E" เป็นคำตอบแบบ 4 คะแนน โดยมีจุดสำคัญดังนี้: อุปกรณ์ส่งสัญญาณ interrupt ที่ทำให้ interrupt flag ใน interrupt register ถูกตั้งขึ้น; โปรเซสเซอร์ตรวจสอบรีจิสเตอร์นี้ที่ ปลายของแต่ละ fetch-execute cycle, หลังจากคำสั่งปัจจุบัน被执行เสร็จ; หากมี flag ถูกตั้งขึ้น且有 interrupt มี priority สูงกว่างานปัจจุบัน, เนื้อหาของ PC และรีจิสเตอร์อื่นๆ จะถูกบันทึกลงบน stack; ที่อยู่ของโปรแกรมบริการ interrupt จะถูกโหลดลงใน PC และโปรแกรมจะทำงาน; เมื่อเสร็จสิ้น ค่าที่บันทึกไว้จะถูกกู้คืนจาก stack และโปรแกรมที่ถูก interrupt จะดำเนินต่อจากจุดที่หยุดอยู่

สาเหตุ worthy of naming: hardware interrupt จากอุปกรณ์ (เช่น กดคีย์, buffer ของ printer ว่าง,数据包 arrives), software interrupt จากความผิดพลาด (เช่น การหารด้วยศูนย์, คำสั่งที่ไม่ถูกต้อง, Arithmetic overflow), timer interrupt จาก OS ที่บ่งชี้ถึงสิ้นสุดของ time slice, และการเตือนเมื่อไฟดับ

แผนภาพขั้นตอนการจัดการสัญญาณขัดจังหวะ: โปรแกรมที่กำลังทำงานถูกขัดจังหวะ, ซีพียูเสร็จสิ้นคำสั่งปัจจุบัน, บันทึกสถานะ (PC และเรจิสเตอร์) ลงบนสตैก, ทำงานฟังก์ชันบริการสัญญาณขัดจังหวะ, ฟื้นฟูสถานะและดำเนินต่อ
วิธีการที่ interrupt เข้ามาเกี่ยวข้องกับวงจร fetching-execute
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
interrupt register/ˈɪntərʌpt ˈredʒɪstə/ Interrupt Register
stack/stæk/ stack
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
ไทย
ผู้เข้าสอบควรสามารถ: หมายเหตุและคำแนะนำ
แสดงความเข้าใจถึงความสัมพันธ์ระหว่าง ภาษาแอสsemblี และ machine code
อธิบายขั้นตอนต่างๆ ของกระบวนการประกอบโปรแกรมสำหรับ ตัวประกอบแบบสองผ่าน (two-pass assembler) นำใช้กระบวนการของ ตัวประกอบแบบสองผ่าน กับโปรแกรมภาษาแอสsemblyที่กำหนดให้
ติดตามการทำงานของโปรแกรมภาษาแอสsemblyที่ง่ายและกำหนดให้
แสดงความเข้าใจว่าชุดคำสั่งถูกจัดกลุ่มเข้าด้วยกัน รวมถึงกลุ่มต่อไปนี้: • การเคลื่อนย้ายข้อมูล • การรับและการส่งข้อมูล • การดำเนินการทางคณิตศาสตร์ • คำสั่งแบบไม่มีเงื่อนไขและคำสั่งที่มีเงื่อนไข • คำสั่งเปรียบเทียบ
แสดงความเข้าใจและสามารถใช้ โหมดการเข้าถึงหน่วยความจำ (modes of addressing) ที่แตกต่างกันได้ รวมถึง แบบทันที (immediate), แบบตรง (direct), แบบอ้อม (indirect), แบบดักจิก (indexed), แบบสัมพัทธ์ (relative)

Source: Cambridge International syllabus · ⁨แหล่งที่มา: หลักสูตร Cambridge International⁩

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 ทำงานจริงด้วย machine code — รูปแบบบิตที่เป็นเฉพาะสำหรับ architecture หนึ่ง Assembly language เป็นรูปแบบที่อ่านเข้าใจได้ ซึ่งมีการใช้ 1 คำสั่งต่อ 1 คำสั่งใน machine code เขียนโดยใช้ mnemonics เช่น LDD, ADD, JMP. Assembler ทำหน้าที่แปลมันเป็น machine code

Assembler แปล mnemonics ของแอสsemblีให้เป็นรูปแบบบิตของ machine code
Assembler แปล mnemonics ให้เป็นรูปแบบบิตของ machine code

Two-pass assembler

Two-pass assembler อ่าน source code สองครั้ง:

  • pass 1 สร้าง symbol table: ทุกครั้งที่ปรากฏ label (เช่น LOOP:), บันทึกที่อยู่ของมัน; ยังไม่มีการสร้างโค้ด
  • pass 2 สร้างโค้ด: แปลแต่ละคำสั่ง, และเมื่อคำสั่งใดอ้างอิงถึง label (เช่น JMP LOOP), ดูหาที่อยู่ของมันใน symbol table

สองรอบช่วยจัดการกับ forward references (การ jump ไปยัง label ที่นิยามไว้ทีหลัง)

ตัวอย่างวิธีทำ. นำกระบวนการสองรอบไปใช้กับโปรแกรมนี้ โดยคำสั่งแรกถูกเก็บอยู่ที่ที่อยู่ 100

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

Pass 1 อ่านแต่ละบรรทัด นับจำนวนที่อยู่ที่จะใช้ และบันทึก label ทั้งหมดลงใน symbol table: LOOP = 101 (บรรทัด DEC) และ COUNT = 105 (บรรทัดข้อมูล). ไม่มีการสร้างโค้ด Pass 2 อ่านโปรแกรมอีกครั้งและแปลแต่ละบรรทัดเป็น machine code โดยแทนที่แต่ละ mnemonic ด้วย opcode และแทนที่ symbolic address ด้วยตัวเลขจาก symbol table: LDD COUNT กลายเป็น opcode สำหรับ LDD ที่มี operand เป็น 105, และ JPN LOOP กลายเป็น opcode สำหรับ JPN ที่มี operand เป็น 101. การ jump กลับไปที่ LOOP อาจแก้ได้ในรอบเดียว แต่การ jump ไปข้างหน้า ไปยัง label ที่ยังไม่เคยเห็นมาก่อนไม่สามารถทำได้ นี่คือเหตุผลที่ assembler ต้องใช้สองรอบ

ตัวอย่างชุดคำสั่ง

Cambridge ใช้เซตทั่วไปขนาดเล็กพิมพ์ในตารางอ้างอิงของข้อสอบ, ซึ่งประกอบด้วยเรจิสเตอร์ใช้งานทั่วไปหนึ่งตัวคือแอคคัมมิเลเตอร์ (ACC), และเรจิสเตอร์อินเด็กซ์ (IX). ตัว operand ที่เขียน #n คือจำนวนฐานสิบ, Bn เป็นจำนวนฐานสอง และ &n เป็นจำนวนฐานสิบหก; <address> คือหมายเลขตำแหน่งหรือฉลาก

กลุ่ม คำสั่ง สิ่งที่ทำ
การเคลื่อนย้ายข้อมูล LDM #n โหลดเลข n ลงใน ACC (immediate)
LDD <address> โหลดเนื้อหาจากที่อยู่ ลงใน ACC (direct)
LDI <address> ที่อยู่ถือที่อยู่อื่น; โหลดเนื้อหาจากที่นั่นลงใน ACC (indirect)
LDX <address> เพิ่ม IX กับที่อยู่แล้วโหลดเนื้อหาจากผลลัพธ์ลงใน ACC (indexed)
LDR #n โหลดเลข n ลงใน IX
MOV <register> คัดลอก ACC ลงในรีจิสเตอร์ที่ระบุชื่อ (IX)
STO <address> เก็บเนื้อหาของ ACC ไว้ที่ที่อยู่
อินพุตและเอาต์พุต IN อ่านการกดคีย์และใส่ ASCII code ลงใน ACC
OUT แสดงออก character ซึ่งมี ASCII code อยู่ใน 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, และตั้งค่า flag
CMI <address> เปรียบเทียบ ACC กับเนื้อหาจากที่อยู่ที่地址位于 (indirect)
กระโดด JMP <address> กระโดดไปยังที่อยู่โดยไม่เงื่อนไข
JPE <address> / JPN <address> กระโดดหากการเปรียบเทียบล่าสุดเป็นสมการ/ไม่สมการ
การจัดการบิต AND, OR, XOR กับ #n, Bn, &n หรือ <address> การดำเนินการระดับบิตบน ACC
LSL #n / LSR #n เลื่อน ACC แบบลอจิก n ตำแหน่งไปทางซ้ายหรือขวา
END สิ้นสุดโปรแกรม

คำถาม "คำสั่งภาษาอัสsembly ถูกจัดกลุ่ม" ต้องการชื่อกลุ่ม และคำสั่งจากแต่ละกลุ่ม: การเคลื่อนย้ายข้อมูล, อินพุตและเอาต์พุต, คณิตศาสตร์, การกระโดดแบบไม่มีเงื่อนไขและแบบมีเงื่อนไข, การเปรียบเทียบ และการจัดการบิต.

Explore · ⁨สำรวจ⁩

How a two-pass assembler works · ⁨วิธีการทำงานของแอสsembl์แบบสองรอบ⁩

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. · ⁨ลองเดินตามกระบวนการดู แอสsembl์จะอ่านโค้ดของคุณสองครั้ง: รอบ 1 จะหาตำแหน่งของแต่ละฉลาก (label) เพื่อให้อรอบ 2 สามารถกรอกที่อยู่ได้ — นั่นคือเหตุผลว่าทำไมการกระโดดไปยังฉลากที่นิยาม ภายหลัง จึงยังทำงานได้⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
assembly language/əˈsemblɪ ˈlæŋɡwɪdʒ/ Assembly Language
machine code/məˈʃiːn kəʊd/ เครื่องมิกซ์โค้ด (machine code)
mnemonics/nɪˈmɒnɪks/ คำย่อโปรแกรม
assembler/əˈsemblə/ assembler
symbol table/ˈsɪmbl ˈteɪbl/ symbol table
label/ˈleɪbl/ ฉลาก
forward references/ˈfɔːwəd ˈrefrənsɪz/ forward references
opcode/ˈɒpkəʊd/ opcode
4.2

Addressing modes · ⁨โหมดการเข้าถึง (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).

ไทย

โหมดการเข้าถึง (หรือ modes of addressing) บอกวิธีการที่ CPU หา operands:

  • การเข้าถึงแบบทันที (immediate addressing) — operand คือค่าที่มีอยู่ในคำสั่ง. LDM #10 โหลด 10.
  • การเข้าถึงโดยตรง (direct addressing) — คำสั่งมีที่อยู่; operand คือค่าที่นั่น. LDD 200.
  • การเข้าถึงแบบอ้อม (indirect addressing) — คำสั่งมีที่อยู่ซึ่งมี ที่อยู่อื่น เป็นข้อมูล. LDI 200.
  • การเข้าถึงแบบดรรชนี (indexed addressing) — ที่อยู่ที่มีผลคือ address + index register; ใช้สำหรับอาร์เรย์. LDX 100 พร้อม IR = 5 อ่านที่อยู่ 105.

(การเข้าถึงแบบสัมพัทธ์ (Relative addressing) ให้ที่อยู่เป็น offset จาก PC — ใช้สำหรับการกระโดด.)

สี่โหมดการเข้าถึงที่เข้าถึง operand ของตน. แบบทันที: LDM #10 ให้ 10 โดยตรง. แบบโดยตรง: LDD 200 อ่านตำแหน่งหน่วยความจำ 200 (=42). แบบอ้อม: LDI 200 อ่านตำแหน่ง 200 (=250) จากนั้นอ่านตำแหน่ง 250 (=99). แบบดรรชนี: LDX 100 พร้อม registers ดัชนี 5 อ่านตำแหน่ง 105 (=7)
วิธีที่แต่ละโหมดการเข้าถึงเข้าถึง operand — แบบทันที, แบบโดยตรง, แบบอ้อม และแบบดรรชนี

ตัวอย่างวิธีทำ. เมมโมรี่มี: ตำแหน่ง 200 = 250, ตำแหน่ง 250 = 99, ตำแหน่ง 105 = 7. เรจิสเตอร์อิน덱ซ์มี 5. ค่าอะไรอยู่ในแอคคัมมิเลเตอร์หลังจาก LDM #200, LDD 200, LDI 200 และ LDX 100? ตรวจสอบว่าแต่ละโหมดต้องมองหาไกลแค่ไหน. LDM #200 คือ immediate - ตัว operand คือตัวเลขที่เขียนไว้ในคำสั่ง ดังนั้นแอคคัมมิเลเตอร์จะเก็บ 200. LDD 200 คือ direct - ไปยังตำแหน่ง 200 และดึงสิ่งที่อยู่ตรงนั้น: 250. LDI 200 คือ indirect - ตำแหน่ง 200 มี 250, ซึ่งเป็น ที่อยู่อื่น, ดังนั้นให้ไปต่อยังตำแหน่ง 250: 99. LDX 100 คือ indexed - เพิ่มค่าเรจิสเตอร์อิน덩์เข้ากับความอยู่, $100 + 5 = 105$, และอ่านตำแหน่ง 105: 7. นับจำนวนครั้งที่ต้องเข้าถึงเพื่อแยกแยะ: immediate 0, direct 1, indirect 2, indexed 1 (เมื่อเพิ่มค่า ин덩์แล้ว)

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
indexed addressing/ˈɪndekst əˈdresɪŋ/ indexed addressing
general-purpose registers/ˈdʒenərəl ˈpɜːpəs ˈredʒɪstəz/ รีจิสเตอร์อเนกประสงค์
addressing mode/əˈdresɪŋ məʊd/ addressing mode
immediate addressing/ɪˈmiːdɪət əˈdresɪŋ/ immediate addressing
direct addressing/daɪˈrekt əˈdresɪŋ/ direct addressing
indirect addressing/ɪndaɪˈrekt əˈdresɪŋ/ indirect addressing
relative addressing/ˈrelətɪv əˈdresɪŋ/ relative addressing
4.2

Tracing an assembly program · ⁨การติดตามโปรแกรมอัสsembly⁩

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, register ดัชนี, ตัวแปรแต่ละตัว และ任何其他标志 (flags). ก้าวผ่านคำสั่ง, อัปเดตตารางหลังจากแต่ละคำสั่ง; ตามเส้นทางเมื่อมีการเปลี่ยน 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

และ seterusnya จนกว่า LDD 200 จะโหลด 0, การเปรียบเทียบตั้งค่า equal flag, JPE 108 ถูกนำไปใช้ และโปรแกรมสิ้นสุด. สามสิ่งที่ผู้ตรวจสอบดู:一个 CMP ไม่เปลี่ยน register ใด ๆ เพียงแต่เปลี่ยน flag; การกระโดดที่ไม่ถูกนำไปใช้ยังคงนับว่าเป็นการดำเนินการ; และ OUT ออกมาตัวอักษร, ดังนั้นมันจึงอยู่ในคอลัมน์เอาต์พุต ไม่ใช่คอลัมน์ ACC. "ระบุผลกระทบของการเปลี่ยน LDD 10 เป็น LDM #10": ACC จะเก็บตัวเลข 10 แทนที่จะเก็บเนื้อหาของที่อยู่ 10.

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
flags/flæɡz/ ธง
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
ไทย
ผู้เข้าสอบควรสามารถ: หมายเหตุและคำแนะนำ
แสดงความเข้าใจและทำ การเลื่อนบิต (binary shifts) ได้ แบบตรรกะ, แบบเลขคณิต และ แบบหมุนวน เลื่อนซ้าย, เลื่อนขวา
แสดงความเข้าใจว่า การจัดการบิต สามารถนำไปใช้ในการตรวจสอบ/ควบคุมอุปกรณ์ได้อย่างไร ดำเนินการ การจัดการบิต ตรวจสอบและตั้งค่าบิต (โดยใช้ การ masks บิต)
ชื่อตำแหน่งคำสั่ง | Opcode | Operand คำอธิบาย
AND #n / Bn / &n การดำเนินการ AND แบบบิตต่อบิตของเนื้อหาใน ACC กับ operand
AND
การดำเนินการ AND แบบบิตต่อบิตของเนื้อหาใน ACC กับเนื้อหาใน
XOR #n / Bn / &n การดำเนินการ XOR แบบบิตต่อบิตของเนื้อหาใน ACC กับ operand
XOR
การดำเนินการ XOR แบบบิตต่อบิตของเนื้อหาใน ACC กับเนื้อหาใน
OR #n / Bn / &n การดำเนินการ OR แบบบิตต่อบิตของเนื้อหาใน ACC กับ operand
OR
การดำเนินการ OR แบบบิตต่อบิตของเนื้อหาใน ACC กับเนื้อหาใน
LSL #n บิตใน ACC会被เลื่อนไปทางซ้าย n ตำแหน่งตามหลักตรรกะ จะเพิ่มค่าศูนย์เข้าไปที่ด้านขวา
LSR #n บิตใน ACC会被เลื่อนไปทางขวา n ตำแหน่งตามหลักตรรกะ จะเพิ่มค่าศูนย์เข้าไปที่ด้านซ้าย
ทำเครื่องหมายชื่อตำแหน่งกับคำสั่ง
ให้ที่อยู่เชิงสัญลักษณ์
ข้อคำถามทั้งหมดจะสมมติว่ามีรีจิสเตอร์ใช้งานทั่วไปเพียงหนึ่งตัว (Accumulator) ACC หมายถึง Accumulator IX หมายถึง Index Register
อาจเป็นที่อยู่แบบabsoluteหรือเชิงสัญลักษณ์ # หมายถึงตัวเลขฐานสิบ เช่น #123 B หมายถึงตัวเลขฐานสอง เช่น B01001010 & หมายถึงตัวเลขฐานหก عشر เช่น &4A

Source: Cambridge International syllabus · ⁨แหล่งที่มา: หลักสูตร Cambridge International⁩

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.

ไทย

การเลื่อนแบบลอจิก (logical shift) เคลื่อนย้ายบิตทั้งหมดไปทางซ้ายหรือขวาตามจำนวนตำแหน่ง, เติมตำแหน่งใหม่ด้วย 0.

  • เลื่อนไปทางซ้าย 1 ตำแหน่ง (LSL #1) — บิตเคลื่อนไปทางซ้าย, 0 เข้ามาทางขวา; สำหรับจำนวนที่ไม่เป็นลบนี่คือ × 2.
  • เลื่อนไปทางขวา 1 ตำแหน่ง (LSR #1) — บิตเคลื่อนไปทางขวา, 0 เข้ามาทางซ้าย; สำหรับจำนวนที่ไม่เป็นลบนี่คือ integer ÷ 2.

การเลื่อน $n$ ตำแหน่ง คูณหรือหารด้วย $2^{n}$. ตัวอย่าง: 00001011 (11) LSL #1 → 00010110 (22).

บิตที่เลื่อนออกจากปลายจะหายไป ดังนั้นการคูณจึงถูกต้องก็ต่อเมื่อบิตเหล่านั้นเป็นศูนย์. LSL #2 บนจำนวนเต็มสองส่วนเติม (two's-complement integer) 11001010 ให้ 00101000: บิต 1 ทั้งสองตัวที่ตกออกทางซ้ายหายไป, บิตเครื่องหมายเปลี่ยนไป, และผลลัพธ์不再是เดิม的四倍.

การเลื่อนทางขวาแบบเลขคณิต (arithmetic right shift) เก็บบิตเครื่องหมายไว้เพื่อให้จำนวนเต็มที่มีเครื่องหมายติดลบยังคงติดลบ. การเลื่อนแบบหมุน (cyclic shift/rotate) นำบิตที่หลุดออก的一端กลับเข้ามา另一端, ดังนั้นไม่มีบิตไหนหาย.

"แสดงผลลัพธ์ของการเลื่อนทางขวาแบบเลขคณิต 3 ตำแหน่งบน 10011110": คัดลอกบิตเครื่องหมายเข้าไปในตำแหน่งที่ถูกว่าง, 11110011. การเลื่อนเดียวกันบน 01011100 ให้ 00001011. การเลื่อนทางซ้ายแบบหมุน 1 บน 10000110 ให้ 00001101: 1 ตัวแรกปรากฏขึ้นทางขวาอีกครั้ง.

สามการเลื่อน 8-บิต: LSL #1 เปลี่ยน 00001011 เป็น 00010110 (คูณ 2, 0 เข้ามาทางขวา); LSR #1 เปลี่ยนเป็น 00000101 (หารด้วย 2, 0 เข้ามาทางซ้าย); ASR #1 เปลี่ยน 10110100 เป็น 11011010, คัดลอกบิตเครื่องหมาย
เลื่อนทางซ้ายแบบลอจิก ($\times 2$), เลื่อนทางขวาแบบลอจิก ($\div 2$) และเลื่อนทางขวาแบบเลขคณิต (เก็บบิตเครื่องหมาย)

ความแตกต่างของการเลื่อนขวาทั้งสองแบบคือ 1 บิต Take 11110000, ซึ่งเป็น 240 อ่านเป็น unsigned และ $-16$ อ่านเป็น signed. LSR #1 นำเข้า 0 และให้ 01111000 $= 120$, ซึ่งเป็นครึ่งที่ถูกต้องของ 240. ASR #1 คัดลอกบิตเครื่องหมายแทนและให้ 11111000 $= -8$, ซึ่งเป็นครึ่งที่ถูกต้องของ $-16$. ไม่มีอย่างใดผิด — แต่ละอย่าง减半ค่าภายใต้การอ่านหนึ่งแบบ

byte 11110000 เลื่อนไปทางขวาสองครั้ง: LSR นำ 0 เข้ามาทางซ้ายให้ 01111000 ซึ่งคือ 120, ในขณะที่ ASR คัดลอกบิตเครื่องหมายให้ 11111000 ซึ่งคือลบ 8; ผลลัพธ์ทั้งสองต่างกันเพียงบิตที่เข้า进来
การเลื่อนทางขวาแบบลอจิกและแบบเลขคณิตบน byte เดียวกัน: แตกต่างกันเพียงบิตที่เข้าทางซ้าย

การจัดการบิตสำหรับการตรวจสอบ/ควบคุม

อุปกรณ์ฝังตัวมักใช้ บิต ของเรจิสเตอร์หนึ่งบิตต่อสัญญาณ (เช่น บิต $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 พร้อมมาส์กที่เขียนเป็นเลขฐานสิบ, เลขฐานสองหรือเลขฐานหก عشر operands. เมื่อ 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 ในตำแหน่งนั้นและ 1 ที่อื่นๆ; เพื่อทดสอบบิต, 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/ บิต (bit)
logical shift/ˈlɒdʒɪkl ʃɪft/ logical shift
cyclic shift/ˈsaɪklɪk ʃɪft/ cyclic shift
mask/mæsk/ mask
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
ไทย

คำถามคำนิยามจะให้คะแนนตามข้อความที่กำหนดไว้你必须 exact. เรียนรู้ให้ถูกต้องและตอบเพียงคำตอบเดียวเท่านั้น

พจน์ นิยาม
แนวคิดโปรแกรมจัดเก็บ คำสั่งโปรแกรมและข้อมูลถูกเก็บไว้ในหน่วยความจำหลักทั้งคู่, และคำสั่งจะถูกดึงและดำเนินการทีละอัน
เรจิสเตอร์ ตำแหน่งจัดเก็บขนาดเล็กและรวดเร็วมากภายในโปรเซสเซอร์เพื่อวัตถุประสงค์เฉพาะ
Program Counter เรจิสเตอร์ที่เก็บที่อยู่ของคำสั่งถัดไปที่จะถูกดึง
Memory Address Register เรจิสเตอร์ที่เก็บที่อยู่ของตำแหน่งหน่วยความจำที่กำลังอ่านหรือเขียน
Memory Data Register เรจิสเตอร์ที่เก็บข้อมูลที่หรือคำสั่งที่ถูกอ่านจากหน่วยความเมมเมื่อเร็วๆ นี้, หรือกำลังจะเขียนลงไปยังหน่วยความจำ
Current Instruction Register เรจิสเตอร์ที่เก็บคำสั่งที่กำลังถูกถอดรหัสและดำเนินการอยู่ในขณะนี้
Accumulator เรจิสเตอร์อเนกประสงค์ที่เก็บผลลัพธ์ของการดำเนินการทางคณิตศาสตร์หรือตรรกะล่าสุด
หน่วยความจำแคช หน่วยความจำขนาดเล็กและรวดเร็วใกล้กับโปรเซสเซอร์เก็บคำสั่งและข้อมูลที่ใช้งานบ่อย
Interrupt สัญญาณจากอุปกรณ์หรือโปรแกรมที่ทำให้โปรเซสเซอร์หยุดงานปัจจุบันชั่วคราวและรันRoutine บริการInterrupt
ภาษาแอสsemblie ภาษาเลเวลต่ำที่คำนำหน้าคำสั่งแต่ละตัวสอดคล้องกับคำสั่งadow code หนึ่งตัว
การเข้าถึงแบบทันที operand คือค่าที่เขียนไว้ในคำสั่ง
การเข้าถึงโดยตรง operand คือเนื้อหา củaที่อยู่ที่เขียนไว้ในคำสั่ง
การเข้าถึงทางอ้อม ที่อยู่ในคำสั่งเก็บที่อยู่ของ operand
การเข้าถึงแบบดัชนี ที่อยู่ของ operand คือที่อยู่ในคำสั่งบวกกับเนื้อหา của index register
การเข้าถึงสัมพัทธ์ ที่อยู่ของ operand ถูกกำหนดเป็นoffset จากที่อยู่ของคำสั่งปัจจุบัน
การเลื่อนเชิงตรรกะ ทุกบิตเคลื่อนที่จำนวนตำแหน่งที่กำหนดและหลักศูนย์เติมเต็มตำแหน่งที่ว่าง
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 ว่า "load 10". LDD 10 โหลดเนื้อหา ของที่อยู่ 10; LDM #10 โหลดตัวเลข 10.
  • การใส่ค่าในคอลัมน์ ACC สำหรับ CMP หรือ OUT. การเปรียบเทียบตั้งค่าflag เท่านั้น; การเอาต์พุตไปที่คอลัมน์เอาต์พุต.
  • การบอกว่าInterrupt ถูกจัดการ "ทันที". โปรเซสเซอร์เสร็จสิ้นคำสั่งปัจจุบันและตรวจสอบInterruptที่สิ้นสุดรอบ.
  • การใช้การเลื่อนทางขวาแบบตรรกะกับเลขtwo's-complement ติดลบ. มีการเลื่อนทางคณิตศาสตร์เท่านั้นที่รักษา sign bit.

Interactive lessons on this topic · ⁨บทเรียนเชิงโต้ตอบสำหรับหัวข้อนี้⁩

Work through it step by step, with instant-check exercises. · ⁨ทำทีละขั้นตอน พร้อมแบบฝึกหัดตรวจสอบผลทันที⁩

Past Papers · ⁨ข้อสอบย้อนหลัง⁩

More topics in A-Level Computer Science · ⁨Computer Science A-Level⁩ · ⁨หัวข้อเพิ่มเติมใน A-Level Computer Science · ⁨Computer Science A-Level⁩⁩

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP