• Bốn nguyên tắc thiết kế cơ bản• Ba toán hạng trong máy tính • Biểu diễn lệnh trong máy tính • Phân loại được lệnh theo 3 định dạng: R-type, I-Type, J-Type • Phân loại được lệnh theo c
Trang 1COMPUTER ARCHITECTURE
Lecture 1
Instruction: Language of the Computer
Chapter 2
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 2• Bốn nguyên tắc thiết kế cơ bản
• Ba toán hạng trong máy tính
• Biểu diễn lệnh trong máy tính
• Phân loại được lệnh theo 3 định dạng:
R-type, I-Type, J-Type
• Phân loại được lệnh theo chức năng
• Chuyển đổi lệnh giữa các ngôn ngữ: cấp cao, hợp ngữ, và ngôn ngữ máy.
Sep-16
The goals
2
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 4• Slide:
Patterson & Hennessy, © 2008, MK
Trang 5• Giới thiệu về lệnh, tập lệnh
• Kiến trúc tập lệnh MIPS
• Phép toán/toán hạng trong máy tính
• Xem lại số có dấu, số không dấu
• Biểu diễn lệnh, phân loại lệnh
Sep-16
Lecture goals
5
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 6• Introduction
• Operations of the Computer Hardware
• Operands of the Computer hardware
• Representing Instruction in Computer
Trang 10• Tập lệnh của một máy tính
• Máy tính khác nhau thì có tập lệnh khác nhau
• Máy tính sơ khai thì có tập lệnh đơn giản
• Nhiều máy tính hiện đại cũng có tập lệnh đơn giản
Sep-16
Instruction Set
10
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 11• Được sử dụng trong môn học
• Cung cấp bởi MIPS Technologies
Trang 12Operations of the Computer Hardware
Arithmetic Operations
• Add và subtract, có 3 toán hạng
Trang 13Operations of the Computer Hardware
Arithmetic Operations
There must certainly be instructions for
performing the fundamental arithmetic
Trang 14Operations of the Computer Hardware
MIPS operands
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 15Operations of the Computer Hardware
MIPS assembly language
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 16Operations of the Computer Hardware
Trang 17Operations of the Computer Hardware
Trang 18Operations of the Computer Hardware
Design Principle 1
• Simplicity favours regularity
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 19Operands of the Computer Hardware
Có ba loại toán hạng:
1 Toán hạng thanh ghi (Register Operand)
2 Toán hạng bộ nhớ (Memory Operand)
3 Toán hạng trực tiếp (Immediate Operand)
Sep-16
Operands
19
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 20Operands of the Computer Hardware
• Các lệnh toán học sử dụng các toán hạng thanh ghi
• MIPS có một tập thanh ghi 32 × 32-bit
• Gọi tên theo chức năng các thanh ghi
• Design Principle 2: Smaller is faster
Trang 21Representing Instructions in the Computer
• Holds thirty-two 32-bit registers
MIPS Register File
Register File
src1 addr src2 addr dst addr write data
32 bits
src1 data
src2 data
32 locations
32 5
32
5 5 32
Faster than main memory
- But register files with more locations are slower (e.g., a 64 word file could be as much
as 50% slower than a 32 word file)
- Read/write port increase impacts speed quadratically
Easier for a compiler to use
- e.g., (A*B) – (C*D) – (E*F) can do multiplies in any order vs stack
Can hold variables so that
- code density improves (since register are named with fewer bits than a memory location)
write control
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 22Operands of the Computer Hardware
$zero 0 constant 0 ( hardware ) n.a.
$at 1 reserved for assembler n.a.
$ra 31 return addr ( hardware ) yes
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 23Operands of the Computer Hardware
Trang 24Operands of the Computer Hardware
Trang 25Operands of the Computer Hardware
• Bộ nhớ chính được sử dụng cho dữ liệu hỗn hợp
• Ứng dụng cho các phép toán số học
• Bộ nhớ được đánh địa chỉ theo byte
• Các word được sắp xếp trong bộ nhớ
• MIPS is Big Endian
• c.f Little Endian: Bit thấp là bit địa chỉ thấp của 1 từ
Memory Operands
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 26Operands of the Computer Hardware
Memory Operands
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 27Operands of the Computer Hardware
Trang 28Operands of the Computer Hardware
add $s1, $s2, $t0
Memory Operand Example 1
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 29Operands of the Computer Hardware
• C code:
A[12] = h + A[8];
• Compiled MIPS code:
Trang 30Operands of the Computer Hardware
• Các thanh ghi thì truy xuất nhanh hơn bộ nhớ
• Hoạt động trên dữ liệu bộ nhớ yều cầu nạp và lưu
dữ liệu
• Trình biên dịch phải sử dụng các thanh ghi cho các biến nhiều nhất có thể
Registers vs Memory
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 31Operands of the Computer Hardware
Trang 32Operands of the Computer Hardware
• Thanh ghi MIPS 0 ($zero) là hằng số zero
• Hữu dụng cho các phép toán phổ biến
add $t2, $s1, $zero
The Constant Zero
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 33Review: Signed and Unsigned Numbers
• Given an n-bit number
Unsigned Binary Integers
0 0
1 1
2 n 2 n
1 n 1
Trang 34Review: Signed and Unsigned Numbers
Review: Unsigned Binary
Trang 35Review: Signed and Unsigned Numbers
• Given an n-bit number
2s-Complement Signed Integers
0 0
1 1
2 n 2 n
1 n 1
Trang 36Review: Signed and Unsigned Numbers
• Bit 31 is sign bit
• Non-negative numbers have the same unsigned
and 2s-complement representation
• Some specific numbers
Trang 37Review: Signed and Unsigned Numbers
Signed Binary
Representation
2 3 - 1 =
-(2 3 - 1) = -2 3 =
1010 complement all the bits
1011 and add a 1
complement all the bits
Trang 38Review: Signed and Unsigned Numbers
• Biểu diễn một số khi sử dụng nhiều bit hơn
• Trong tập lệnh MIPS
• addi: extend immediate value
• lb, lh: extend loaded byte/halfword
• beq, bne: extend the displacement
• Nhân rộng các bit dấu bên trái
• Examples: 8-bit to 16-bit
Trang 39Representing Instructions in the Computer
• Design-time metrics:
• Can it be implemented? With what performance, at what costs (design,
fabrication, test, packaging), with what power, with what reliability?
• Can it be programmed? Ease of compilation?
• Static Metrics:
• How many bytes does the program occupy in memory?
• Dynamic Metrics:
• How many instructions are executed? How many bytes does the processor
fetch to execute the program?
• How many clocks are required per instruction?
• How "lean" a clock is practical?
Best Metric: Time to execute the program!
Review : Evaluating ISAs
CPI
Inst Count Cycle Time
depends on the instructions set, the processor
organization, and compilation techniques.
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 40Representing Instructions in the Computer
1 Instructions are represented as numbers and, as such, are
indistinguishable from data
2 Programs are stored in alterable memory (that can be
read or written to)
just like data
Two Key Principles of Machine
Design
Stored-program concept
Programs can be shipped as files of
binary numbers – binary compatibility
Computers can inherit ready-made
software provided they are
compatible with an existing ISA – leads
industry to align around a small
number of ISAs
Accounting prg (machine code)
C compiler (machine code) Payroll data
Source code in C for Acct prg
Memory
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 41Representing Instructions in the Computer
• Simplicity favors regularity
• fixed size instructions
• small number of instruction formats
• opcode always the first 6 bits
• Smaller is faster
• limited instruction set
• limited number of registers in register file
• limited number of addressing modes
• Make the common case fast
• arithmetic operands from the register file (load-store
machine)
• allow instructions to contain immediate operands
• Good design demands good compromises
• three instruction formats
MIPS (RISC) Design Principles
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 42Representing Instructions in the Computer
• Phân loại theo chức năng
Trang 43Lecture review
• Các trường của MIPS
MIPS Instruction Fields
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
Op: phép toán cơ bản của lệnh, thương được gọi là opcode(mã lệnh)
Rt: toán hạngRs : toán hạng thanh ghi thứ nhất
Rd: toán hạng thanh ghi đích Nơi lưu kết quả của phéptoán
Shamt: shit amount
Funct: trường này thường được gọi là mã hàm (functioncode), chọn biến cụ thể của phép toán trong trường mã lệnh
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 44Lecture review
• Có tất cả bao nhiêu lệnh MIPS được biểu diễn?
• Tầm địa chỉ của lệnh I-TYPE?
• Tầm địa chỉ của lệnh J-Type?
Question
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 45Lecture review
Có 4 nguyên tắc thiết kế cơ bản:
1 Simplicity favors regularity
2 Smaller is faster
3 Make the common case fast
4 Good design demands good compromises
MIPS (RISC) Design Principles
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 46Lecture review
Có ba loại toán hạng:
1 Toán hạng thanh ghi (Register Operand)
2 Toán hạng bộ nhớ (Memory Operand)
3 Toán hạng trực tiếp (Immediate Operand)
Sep-16
Operands of the computer hardware
46
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 47Lecture review
• Các trường của MIPS
MIPS Instruction Fields
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
Op: phép toán cơ bản của lệnh, thương được gọi là opcode(mã lệnh)
Rs : toán hạng thanh ghi thứ nhất
Rt: toán hạng nguồn thanh ghi thứ hai
Rd: toán hạng thanh ghi đích Nơi lưu kết quả của phéptoán
Shamt: shit amount
Funct: trường này thường được gọi là mã hàm (functioncode), chọn biến cụ thể của phép toán trong trường mã lệnh
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 48Lecture review
Sep-16
Instruction format
op op op
R format: Các lệnh có các toán hạng là toán hạng thanh ghi
I format: Các lệnh có các toán hạng là toán hạng bộ nhớ
J format: Các lệnh nhảy (Jump)
48
CuuDuongThanCong.com https://fb.com/tailieudientucntt
Trang 49Lecture review
Sep-16
MIPS instruction class
Instruction class MIPS example