You are on page 1of 31

VIETNAM NATIONAL UNIVERSITY HANOI (VNU)

INFORMATION TECHNOLOGY INSTITUTE

Computer Architecture
Lecture 2: Basic Components

Duy-Hieu Bui, PhD


AIoT Research Laboratory
Email: hieubd@vnu.edu.vn
https://duyhieubui.github.io
Nội dung

1. Nguyên tắc chung

2. Các thành phần cơ bản

3. Chức năng chính

4. Cơ chế ngắt và chu trình lệnh đầy đủ

Tham khảo chương 3 của “Computer Organization and Architecture:


Designing for Performance”, William Stallings, 10th edition
5/9/2019 Duy-Hieu Bui 2
1. Khái niệm chương trình

• Chương trình cứng hoá không cho phép thay đổi

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

• Chuỗi các bước


(a) Programming in hardware
• Với mỗi bước, một phép tính logic/số học được thực hiện
• Mỗi phép tính khác nhau được xác định bởi 1 tập các tín hiệu
điều khiển khác nhau

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

5/9/2019 Duy-Hieu Bui 5


Nguyên tắc chung

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ể)

5/9/2019 Duy-Hieu Bui 6


Minh hoạ chương trình với MARS

5/9/2019 Duy-Hieu Bui 7


2. Thành phần máy tính

• Central Processing Unit: Control Unit & Arithmetic and Logic


Unit

• Input/Output: dữ liệu và các lệnh cần phải được nạp vào hệ


thống cũng như kết xuất kết quả

• 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

5/9/2019 Duy-Hieu Bui 8


Thành phần: mức tổng quan
CPU Main Memory
0
System 1
2
PC MAR Bus
Instruction
Instruction
Instruction
IR MBR

I/O AR
Data
Execution
unit Data
I/O BR Data
Data

I/O Module n–2


n–1

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

5/9/2019 Duy-Hieu Bui 9


Kiến trúc của máy tính IAS

5/9/2019 Duy-Hieu Bui 10


3. Chức năng máy tính

• 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

Fetch Cycle Execute Cycle

Fetch Next Execute


START HALT
Instruction Instruction

5/9/2019 Duy-Hieu Bui 11


Chu trình fetch

• 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)

• Lệnh được tải lên thành ghi IR - Instruction Register

5/9/2019 Duy-Hieu Bui 12


Chu trình thực thi

• Processor dịch lệnh và thực thi các phép toán tương ứng

Chu trình thực thi bao gồm những kiểu sau:


• Chuyển dữ liệu
– Processor-memory (data transfer between CPU and main memory)
– Processor - I/O (Data transfer between CPU and I/O module)
• Xử lý dữ liệu - Data processing
– Some arithmetic or logical operation on data
• Điều khiển - Control
– Thi hành các lệnh của CPU thông qua việc biến đổi thành chuỗi các
thao tác logic cơ bản

5/9/2019 Duy-Hieu Bui 13


Các loại thao tác

• Dữ liệu chuyển • Dữ liệu được


từ CPU đến MM chuyển từ I/O đến
và từ MM đến CPU và từ CPU đến
CPU trực tiếp I/O

Processor- Processor-
memory I/O

Data
Control
processing

• Lệnh điều khiển • CPU thi hành


cho phép thay các phép toán
đổi chuỗi thi ALU
hành các phép
toán/thao tác
5/9/2019 Duy-Hieu Bui 14
Máy tính đơn giản

0 3 4 15
Opcode Address

(a) Instruction format

0 1 15
S Magnitude

(b) Integer format

Program Counter (PC) = Address of instruction


Instruction Register (IR) = Instruction being executed
Accumulator (AC) = Temporary storage

(c) Internal CPU registers

0001 = Load AC from Memory


0010 = Store AC to Memory
0101 = Add to AC from Memory

(d) Partial list of opcodes


5/9/2019 Duy-Hieu Bui 15
Ví dụ

Memory CPU Registers Memory CPU Registers


300 1 9 4 0 3 0 0 PC 300 1 9 4 0 3 0 1 PC
301 5 9 4 1 AC 301 5 9 4 1 0 0 0 3 AC
302 2 9 4 1 1 9 4 0 IR 302 2 9 4 1 1 9 4 0 IR
• •
• •
940 0 0 0 3 940 0 0 0 3
941 0 0 0 2 941 0 0 0 2
Step 1 Step 2
Memory CPU Registers Memory CPU Registers
300 1 9 4 0 3 0 1 PC 300 1 9 4 0 3 0 2 PC
301 5 9 4 1 0 0 0 3 AC 301 5 9 4 1 0 0 0 5 AC
302 2 9 4 1 5 9 4 1 IR 302 2 9 4 1 5 9 4 1 IR
• •
• •
940 0 0 0 3 940 0 0 0 3 3+2=5
941 0 0 0 2 941 0 0 0 2
Step 3 Step 4
Memory CPU Registers Memory CPU Registers
300 1 9 4 0 3 0 2 PC 300 1 9 4 0 3 0 3 PC
301 5 9 4 1 0 0 0 5 AC 301 5 9 4 1 0 0 0 5 AC
302 2 9 4 1 2 9 4 1 IR 302 2 9 4 1 2 9 4 1 IR
• •
• •
940 0 0 0 3 940 0 0 0 3
941 0 0 0 2 941 0 0 0 5
Step 5 Step 6
5/9/2019 Duy-Hieu Bui 16
Luồng điền khiển của máy tính IAS

5/9/2019 Duy-Hieu Bui 17


4. Sơ đồ trạng thái chu trình lệnh

Instruction Operand Operand


fetch fetch store

Multiple Multiple
operands results

Instruction Instruction Operand Operand


Data
address operation address address
Operation
calculation decoding calculation calculation

Return for string


Instruction complete, or vector data
fetch next instruction

Figure 3.6 Instruction Cycle State Diagram

5/9/2019 Duy-Hieu Bui 18


Interrupts

• Cơ chế cho phép các modules khác (I/O) có thể tạm


dừng chuỗi xử lý hiện hành (normal sequence of
processing) để thực thi các lệnh của các modules đó
• Các kiểu ngắt thông dụng
– Program
• e.g. overflow, division by zero
– Timer
• Generated by internal processor timer
• Used in pre-emptive multi-tasking
– I/O
• from I/O controller
– Hardware failure
• e.g. memory parity error

5/9/2019 Duy-Hieu Bui 19


Ví dụ
User I/O User I/O User I/O
Program Program Program Program Program Program

1 4 1 4 1 4

I/O I/O I/O


Command Command Command
WRITE WRITE WRITE
5
2a
END
2 2

Interrupt Interrupt
2b Handler Handler

WRITE WRITE 5 WRITE 5

END END
3a

3 3

3b

WRITE WRITE WRITE

(a) No interrupts (b) Interrupts; short I/O wait (c) Interrupts; long I/O wait

= interrupt occurs during course of execution of user program


5/9/2019 Duy-Hieu Bui 20
Ví dụ 1
Time

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

(b) With interrupts


3

(a) Without interrupts


5/9/2019 Duy-Hieu Bui 21
Ví dụ 2
Time

1 1

4 4

I/O operation; 2 I/O operation


processor waits concurrent with
processor executing;
then processor
waits
5

5
2
4
4
3 I/O operation
concurrent with
I/O operation; processor executing;
processor waits then processor
waits

5
5

3 (b) With interrupts

(a) Without interrupts

5/9/2019 Duy-Hieu Bui 22


Figure 3.11 Program Timing: Long I/O Wait
Chu trình ngắt

• Được thêm vào sơ đồ chu trình lệnh để xử lý các yêu cầu


ngắt

• 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

5/9/2019 Duy-Hieu Bui 23


Ví dụ

User Program Interrupt Handler

i
Interrupt
occurs here i+1

5/9/2019 Duy-Hieu Bui 24


Figure 3.8 Transfer of Control via Interrupts
Chu trình lệnh có ngắt

Fetch Cycle Execute Cycle Interrupt Cycle

Interrupts
Disabled
Check for
Fetch Next Execute
START Interrupt;
Instruction Instruction Interrupts Process Interrupt
Enabled

HALT

Figure 3.9 Instruction Cycle with Interrupts


5/9/2019 Duy-Hieu Bui 25
Sơ đồ trạng thái chu trình lệnh

Instruction Operand Operand


fetch fetch store

Multiple Multiple
operands results

Instruction Instruction Operand Operand


Data Interrupt
address operation address address Interrupt
Operation check
calculation decoding calculation calculation

No
Instruction complete, Return for string interrupt
fetch next instruction or vector data

Figure 3.12 Instruction Cycle State Diagram, With Interrupts


5/9/2019 Duy-Hieu Bui 26
Đa ngắt - Multiple Interrupts

• 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 đó

5/9/2019 Duy-Hieu Bui 27


Đa ngắt tuần tự

Interrupt
User program handler X

Interrupt
handler Y

(a) Sequential interrupt processing

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

(b) Nested interrupt processing

Figure 3.13 Transfer of Control with Multiple Interrupts


5/9/2019 Duy-Hieu Bui 29
Mô hình thời gian thi hành đa ngắt

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

5/9/2019 Duy-Hieu Bui 30


Tổng kết

• Nắm rõ khái niệm chương trình cứng, chương trình mềm

• Ba nguyên tắc chính xây dựng mô hình kiến trúc Von


Neuman

• Các chức năng và thành phần chính của máy tính

• Chu trình lệnh đầy đủ (có kèm cơ chế cho phép xử lý ngắt)

5/9/2019 Duy-Hieu Bui 31

You might also like