Professional Documents
Culture Documents
Computer Architecture
Course ID: IT3283
Chương 5
BỘ XỬ LÝ
Đơn vị
Đơn vị Tập
số học
điều khiển thanh ghi
và logic
(CU) (RF)
(ALU)
Đơn vị
số học và logic
Các tín hiệu (ALU)
từ đơn vị
điều khiển
Thanh ghi cờ
Thanh ghi cờ: hiển thị trạng thái của kết quả phép toán
n Một vi chương trình bao Clock Mạch dãy Thanh ghi địa chỉ vi lệnh
(microinstruction)
Bộ nhớ
n Mỗi vi lệnh mã hoá cho vi chương trình
C0 C1 ... C
m-1
Nhiều Nhiều
toán toán
hạng hạng
Có
Tính Giải mã Tính Tính ngắt
địa chỉ Thao tác Kiểm tra
thao tác địa chỉ địa chỉ Ngắt
của lệnh dữ liệu ngắt
lệnh toán hạng toán hạng
Không
Lệnh hoàn thành, Quay lại với dữ liệu ngắt
nhận lệnh tiếp theo String hoặc Vector
CPU
PC
Bộ nhớ
Đơn vị
điều khiển
IR
CPU
MAR
Đơn vị
Bộ nhớ
điều khiển
MBR
CPU
MAR
Đơn vị
Bộ nhớ
điều khiển
MBR
CPU
SP MAR
PC
Đơn vị
Bộ nhớ
điều khiển
MBR
n
Instruction Instruction
address address
on Instruction Instruction
memory memory
FIGURE 4.5 Two state elements are needed to store and access instructions, and an
and an the next instruction address. The state elements are the instruction
n
o compute the next instruction Thanh ghi 32-bit chứa địa chỉ của lệnh hiện tại
state elements are needed to store and access
adder is needed to compute
memory address.
adder
memory
The statecounter.
and the program elements
is needed to compute
instructions,
the next
andare instruction
thethe
program address.
counter.
instruction
The state elements
The instruction memory needare the instruction
only provide read access because the
datapath does not write instructions. Since the instruction memory only reads, the
Th e instruction memory need only provide read access because we treat it as combinational
ogram counter. The instruction datapath
memorydoes need only provide readSinceaccess because thememory only reads, we treat it as combinational
Địa chỉ khởi động = 0xBFC0 0000
n instruction
ite instructions. Since the memory
logic: the
not write instructions.
output only
at anyreads,
logic:
weects
timecontrol
refl
the
treat
output
the it as
the
at instruction
any time
combinational
contents of the
refl ects
location
the contents
specifi ed
of
by
the
the
location
address
specifi
input,
ed
and
by
no
the address input, and no read
read
signal is needed. (We will need to write the instruction memory when we load the program; this is
ny time reflects the contents of the location
control signalspecifi ed by(We
is needed. the
notaddress
will
hardneed input,
to add, andand
to write no
theignore
we read
instruction memory when
it for simplicity.) we loadcounter
The program the program; thisregister
is a 32-bit is that is written at the
ed. (We will need Bộ nhớ lệnh (Instruction memory):
nto write the instruction memory whenend
not hard to
every
add,
clock
and we
cycle
ignore
and
we ofload
it
thus
add
for
its
every
does
two
theclock
not
program;
simplicity.)
need
32-bit
Th e
cycle and
we ignore it for simplicity.) The program counter is a 32-bit register that is written at the thesignal.
end of a
inputswrite
this
program
and
thusis does not need a write control signal. The adder is an ALU wired to always
control
place
counter is
sum on
a 32-bit
Thits
e adder
register that is written
is an ALU wired to always
output.
at the
addcontrol
its two 32-bit
signal.inputs and place theALUsum wired
on its output.
cle and thus does not need a write
n Chứa các lệnh của chương trình
uts and place the sum on its output.
The adder is an to always
n Khiwhich
có địa chỉ lệnh
were introduced
từ
which PC
were
in Chapter
instruction
đưa
is add
đến
introduced
2. Recall
thì
$t1,$t2,$t3,
lệnh
in Chapter được
2. Recall
that a typical
thatđọc
instance
which
ra
a typical
of such
reads $t2
instance of such an
an and writes $t1.
and $t3
instruction is add $t1,$t2,$t3, which reads $t2 and registers
$t3 andare writes
n Bộ 2.cộng (Add): được sử dụng tăng nội dung PC thêm 4 can be
The processor’s 32 general-purpose $t1.
stored in a structure called a
roduced in Chapter Recall that a typical instance of such an
registerTh fiele processor’s
A state 32register file. A register
general-purpose registers
file isare stored inofa registers
a collection structureincalled
whichaany register
ddregister
$t1,$t2,$t3, which
element reads
that $t2
consists and $t3 and writesby $t1.
r’selement để
file A state
32 general-purpose
that consists trỏ
of a set tới
register
registers
of lệnh
file.
are
registers stored
that kế
A register
read or written by specifying in tiếp
read
fileor
a
iswritten
a collection
structure
containsthe thenumber
specifying
called
register of a
state
the number
of registers
theofregister
in whichofany
the computer.
the register in
In Th
in the file. addition,
thebefile. The register file
can
wefiwill
e register le need an ALU to
egister file can
is a collection be read and
of registers written
in which
of a set of registers that
by contains
supplying a the register
register stateany
operate register
of on
thethe canread
values
computer. beIn from the registers.
addition, we will need an ALU to
can be read and written
by specifying the numberNKK-CA2021.1.0
of tothe register in the file. Thethe
R-format register
instructions
IT3283-Kiến trúc
filehave three register operands, so we will need to39read two
máy tính
operate
number beon the values
accessed. read from registers.
by supplying a register data words from the register file and write one data word into the register file for
Thực hiện phần nhận lệnh
Increment by 4
for next
instruction
32-bit
register
op rs rt rd shamt funct
31:26 25:21 20:16 15:11 10:6 5:0
a. Registers
n Tập thanh ghi (Registers): có 32 thanh ghi b.32-bit, ALU
mỗi thanh ghi
đượcFIGURE
xác4.7định bởi số hiệu 5-bit
The two elements needed to implement R-format ALU operations are the
register file and the ALU. The register file contains all the registers and has two read ports and one write
n Read register 1, Read register 2: các đầu vào
port. The design of multiported register files is discussed in Section C.8 of
để chọn các thanh ghi cần đọc
Appendix C. The register file
always outputs the contents of the registers corresponding to the Read register inputs on the outputs; no
n Write register: đầu vào để chọn thanh ghi cần ghi
other control inputs are needed. In contrast, a register write must be explicitly indicated by asserting the
write control signal. Remember that writes are edge-triggered, so that all the write inputs (i.e., the value to
n Read data 1, Read data 2: hai đầu ra dữ liệu đọc từ thanh ghi (32-bit)
be written, the register number, and the write control signal) must be valid at the clock edge. Since writes to
the register file are edge-triggered, our design can legally read and write the same register within a clock cycle:
n Write
the read Data:
will get theđầu vào
value written dữ liệu
in an earlier ghi
clock vào
cycle, thanh
while the valueghi (32-bit)
written will be available to a read in
a subsequent clock cycle. The inputs carrying the register number to the register file are all 5 bits wide, whereas
n RegWrite:
the lines carrying tín
datahiệu điều
values are 32 bitskhiển
wide. Theghi dữ
operation liệu
to vào
be performed
the ALU operation signal, which will be 4 bits wide, using the ALU designed in
thanh ghi
by the ALU is controlled with
Appendix C. We will
n ALU use
đểthethực hiện các phép toán số học/logic
Zero detection output of the ALU shortly to implement branches. The overflow output will not be
needed until Section 4.9, when we discuss exceptions; we omit it until then.
op rs rt imm
31:26 25:21 20:16 15:0
4 or 5 rs rt imm
31:26 25:21 20:16 15:0
Just
re-routes
wires
Sign-bit wire
replicated
• ALUSrc: tín hiệu điều khiển chọn toán hạng đưa đến ALU:
• Lệnh kiểu R: toán hạng từ thanh ghi nguồn thứ hai
• Lệnh lw/sw: Hằng số imm 16-bit được mở rộng thành 32-bit (tính địa chỉ)
• MemtoReg: tín hiệu điều khiển chọn dữ liệu đưa về thanh ghi đích:
• Lệnh kiểu R: lấy kết quả từ ALU result
• Lệnh lw: dữ liệu đọc (Read data) từ bộ nhớ dữ liệu
NKK-CA2021.1.0 IT3283-Kiến trúc máy tính 52
Datapath đơn giản cho các lệnh R/lw/sw/branch
• PCSrc: tín hiệu điều khiển chọn giá trị cập nhật PC
• Không rẽ nhánh: PC ß PC+4
• Rẽ nhánh: PC ß (PC+4) + (hằng số imm đã mở rộng thành 32-bit << 2)
NKK-CA2021.1.0 IT3283-Kiến trúc máy tính 53
2. Thiết kế Control Unit
§ Đơn vị điều khiển có hai phần:
§ Bộ điều khiển ALU
§ Bộ điều khiển chính
lw/sw 35 or 43 rs rt imm
31:26 25:21 20:16 15:0
beq 4 rs rt imm
31:26 25:21 20:16 15:0
Tên tín hiệu Hiệu ứng khi tín hiệu = 0 Hiệu ứng khi tín hiệu = 1
RegDst Số hiệu thanh ghi đích là các bit Số hiệu thanh ghi đích là các bit 15:11 (rd)
20:16 (rt)
Branch Không có lệnh rẽ nhánh beq Có lệnh rẽ nhánh beq
(Branch =1) & (Zero=1): rẽ nhánh xảy ra
(Branch =1) & (Zero=0): rẽ nhánh không
xảy ra
RegWrite Không làm gì cả Ghi dữ liệu trên đầu vào Write Data ở tập
thanh ghi đến thanh ghi đích
ALUSrc Toán hạng thứ hai của ALU lấy Toán hạng thứ hai của ALU là giá trị 16 bit
từ thanh ghi nguồn thứ hai thấp của lệnh (bits 15:0) được mở rộng có
(Read data 2) dấu thành 32-bit
PCSrc PC ß PC+4 PC ß địa chỉ đích
Tên tín hiệu Hiệu ứng khi tín hiệu = 0 Hiệu ứng khi tín hiệu = 1
MemRead Không làm gì cả Nội dung ngăn nhớ dữ liệu, được xác định
bởi địa chỉ do ALU tính, được đưa ra đầu
ra Read data của bộ nhớ dữ liệu
MemWrite Không làm gì cả Dữ liệu trên đầu vào Write Data của bộ
nhớ dữ liệu được ghi vào ngăn nhớ có địa
chỉ do ALU tính
MemtoReg Giá trị được đưa đến đầu vào Giá trị được đưa đến đầu vào Write data
Write data của tập thanh ghi là của tập thanh ghi là từ bộ nhớ dữ liệu
từ ALU result
2 address
31:26 25:0
1 2 3 4 5 6 7 8 9 10 11 12 t
IF ID EX MEM WB
lệnh 1
IF ID EX MEM WB
lệnh 2
IF ID EX MEM WB
lệnh 3
IF ID EX MEM WB
lệnh 4
IF ID EX MEM WB
lệnh 5
IF ID EX MEM WB
lệnh 6
IF ID EX MEM WB
lệnh 7
IF ID EX MEM WB
lệnh 8
§ Hazard: Tình huống ngăn cản bắt đầu của lệnh tiếp
theo ở chu kỳ tiếp theo
§ Hazard cấu trúc: do tài nguyên được yêu cầu đang bận
§ Hazard dữ liệu: cần phải đợi để lệnh trước hoàn thành
việc đọc/ghi dữ liệu
§ Hazard điều khiển: do rẽ nhánh gây ra
Prediction
correct
Prediction
incorrect
Lệnh 2
Lệnh 3
Lệnh 4
Lệnh 5
Lệnh 6
Lệnh 2
Lệnh 3
Lệnh 4
Lệnh 5
Lệnh 6
Hết chương 5