Professional Documents
Culture Documents
Computer Architecture
Lecture 2: Basic Components
Sequence of
Data arithmetic Results
and logic
functions
(a) Programming
Programming in in hardware
hardware
• Phần cứng đa dụng: có thể làm nhiều tác vụ khác nhau, kiểm
soát bằng các tín hiệu điều khiển
Instruction Instruction
• Chương trình
codesmềm: Thay vì thiết kế lại mạch - re-wiring, cung
interpreter
cấp một tập mới các tín hiệu điều khiển
Control
signals
5/9/2019 Duy-Hieu Bui 3
Sequence of
arithmetic
Khái niệm
Data chương trình…
and logic
Results
functions
Instruction Instruction
codes interpreter
Control
signals
General-purpose
Data arithmetic Results
and logic
functions
5/9/2019
Programming
(b) Programming in software
in software
Duy-Hieu Bui 4
Mô hình máy tính vạn năng
1. Dữ liệu và chương trình (lệnh) được lưu giữ trên cùng bộ nhớ
2. Nội dung bộ nhớ xác định thông qua địa chỉ vị trí, không phụ
thuộc vào kiểu dữ liệu đã lưu
3. Chương trình được thi hành tuần tự từ lệnh này đến lệnh kế
tiếp (ngoại trừ những thay đổi cụ thể)
• Main memory: lưu trữ lệnh và dữ liệu tạm thời trong quá trình
tính toán
• Hệ thống liên kết: kết nối, truyền thông các thành phần chính
nêu trên
I/O AR
Data
Execution
unit Data
I/O BR Data
Data
PC = Program counter
Buffers IR = Instruction register
MAR = Memory address register
MBR = Memory buffer register
I/O AR = Input/output address register
I/O BR = Input/output buffer register
• Thực thi chương trình, đã được xây dựng thông qua tập các
lệnh của CPU, lưu trong bộ nhớ
• Các bước chính khi thực thi chương trình trong CPU
– Đọc lệnh từ bộ nhớ (fetch)
– Thực thi lệnh (execute)
– Lưu kết quả trong bộ nhớ (store)
• Chu trình lệnh đơn giản
• Program Counter (PC) lưu địa chỉ lệnh kế tiếp sẽ được tải lên
• Processor tải lệnh từ bộ nhớ xác định bởi địa chỉ lưu trong
PC
• Tăng giá trị PC (ngoại trừ những trường hợp tự xác định)
• Processor dịch lệnh và thực thi các phép toán tương ứng
Processor- Processor-
memory I/O
Data
Control
processing
0 3 4 15
Opcode Address
0 1 15
S Magnitude
Multiple Multiple
operands results
1 4 1 4 1 4
Interrupt Interrupt
2b Handler Handler
END END
3a
3 3
3b
(a) No interrupts (b) Interrupts; short I/O wait (c) Interrupts; long I/O wait
1 1
4 4
I/O operation
I/O operation;
processor waits 2a concurrent with
processor executing
5 5
2b
2
4
I/O operation
4 3a concurrent with
processor executing
I/O operation;
processor waits 5
5 3b
1 1
4 4
5
2
4
4
3 I/O operation
concurrent with
I/O operation; processor executing;
processor waits then processor
waits
5
5
• Quy trình
– Processor checks for interrupt
• Indicated by an interrupt signal
– If no interrupt, fetch next instruction
– If interrupt pending:
• Suspend execution of current program
• Save context
• Set PC to start address of interrupt handler routine
• Process interrupt
• Restore context and continue interrupted program
i
Interrupt
occurs here i+1
Interrupts
Disabled
Check for
Fetch Next Execute
START Interrupt;
Instruction Instruction Interrupts Process Interrupt
Enabled
HALT
Multiple Multiple
operands results
No
Instruction complete, Return for string interrupt
fetch next instruction or vector data
• Disable interrupts
– Trong khi xử lý 1 ngắt, processor sẽ tạm thời bỏ tất qua các ngắt còn
lại
– Các ngắt còn lại sẽ ở trạng thái treo và được xử lý khi ngắt hiện thời
đã được xử lý xong
– Các ngắt được xử lý theo thứ tự yêu cầu
• Define priorities
– Các ngắt có độ ưu tiên thấp có thể bị ngắt bởi các ngắt có độ ưu tiên
cao hơn
– Khi ngắt có độ ưu tiên cao hơn được xử lý xong, processor sẽ quay lại
xử lý tiếp ngắt trước đó
Interrupt
User program handler X
Interrupt
handler Y
Interrupt
User program handler X
5/9/2019 Duy-Hieu Bui 28
Đa ngắt lồng nhau
(a) Sequential interrupt processing
Interrupt
User program handler X
Interrupt
handler Y
Printer Communication
User program
interrupt service routine interrupt service routine
t=0
15
0 t=
t =1
t = 25
t= t = 25 Disk
40 interrupt service routine
t=
35
• Chu trình lệnh đầy đủ (có kèm cơ chế cho phép xử lý ngắt)