Tải bản đầy đủ (.pdf) (50 trang)

kiến trúc máy tính trương văn cường lecture 02 chương ter 02 language of the computer 01 sv sinhvienzone com

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (885.18 KB, 50 trang )

COMPUTER ARCHITECTURE

Chapter 2
Lecture 1

Instruction: Language of
the Computer

CuuDuongThanCong.com

/>

The goals
• 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: Rtype, 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.
2

Sep-16

CuuDuongThanCong.com

/>

Chapter contents
1. Introduction
2. Operations/operands of the Computer


Hardware
3. Signed and Unsigned number (review)
4. MIPS Instruction
5. Arithmetic instruction
6. Logical instruction
7. Branch/jump instruction
3

Sep-16

CuuDuongThanCong.com

/>

References
• Slide:
• Computer Organization and Design, 4th Edition,
Patterson & Hennessy, © 2008, MK
• Mary Jane Irwin, Penn State University

• Textbook: Chương 2 (p.74 – p.221)
• Software:
• Mars / Qtspim

• MIPS reference Data
• Resources:
• />• />4

Sep-16


CuuDuongThanCong.com

/>

Lecture goals
• 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

5

Sep-16

CuuDuongThanCong.com

/>

Lecture contents
• Introduction
• Operations of the Computer Hardware
• Operands of the Computer hardware
• Representing Instruction in Computer
Hardware
• Instruction class

6

Sep-16


CuuDuongThanCong.com

/>

§2.1 Introduction

Brainstorming ...

7

Sep-16

CuuDuongThanCong.com

/>

Brainstorming...

Computer language
8

Sep-16

CuuDuongThanCong.com

/>

Definitions
• Để ra lệnh cho phần

cứng máy tính, cần
ngôn ngữ của phần
cứng máy tính:
• Instruction: lệnh
• Instruction set: Tập
lệnh, hay có thể gọi là
từ vừng của máy tính

Sep-16

9

Introduction

CuuDuongThanCong.com

/>

Instruction Set
• 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
• Nhưng với nhiều khía cạnh là giống nhau

• Máy tính sơ khai thì có tập lệnh đơn giản
• Sự thực hiện đơn giản

• Nhiều máy tính hiện đại cũng có tập lệnh đơn giản

Sep-16


CuuDuongThanCong.com

10

Introduction

/>

The MIPS Instruction Set
• Được sử dụng trong môn học
• Cung cấp bởi MIPS Technologies
www.mips.com
• Chiếm phần lớn trong thị trường chip nhúng
• Ứng dụng trong các lĩnh vực electronics,
network/storage equipment, cameras, printers, …

Sep-16

CuuDuongThanCong.com

11

Introduction

/>

§2.2 Operations of the Computer Hardware

Arithmetic Operations
• Add và subtract, có 3 toán hạng

• 2 toán hạng nguồn, 1 toán hạng đích

add a, b, c # a = b + c
• Tất cả các phép toán đều có dạng như trên.

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware

/>
12


§2.2 Operations of the Computer Hardware

Arithmetic Operations

There must certainly be instructions for
performing the fundamental arithmetic
operations.
Burks, Goldstine, and von Neumann, 1947

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware


/>
13


MIPS operands

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware

/>
14


MIPS assembly language

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware

/>
15


Arithmetic Example


• C code:

f = (g + h) - (i + j);

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware

/>
16


Arithmetic Example
• Compiled MIPS code:
add t0, g, h

# temp t0 = g + h

add t1, i, j

# temp t1 = i + j

sub f, t0, t1

# f = t0 - t1

Sep-16


CuuDuongThanCong.com

Operations of the Computer Hardware

/>
17


Design Principle 1
• Simplicity favours regularity
• Regularity makes implementation simpler
• Simplicity enables higher performance at lower cost

Sep-16

CuuDuongThanCong.com

Operations of the Computer Hardware

/>
18


Operands
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

CuuDuongThanCong.com

Operands of the Computer Hardware

/>
19


• 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
• Sử dụng cho việc truy xuất dữ liệu thường xuyên
• Được đánh số 0-31
• 32-bit data called a “word”

• Gọi tên theo chức năng các thanh ghi
• $t0, $t1, …, $t9 for temporary values
• $s0, $s1, …, $s7 for saved variables

• Design Principle 2: Smaller is faster

Sep-16

CuuDuongThanCong.com

Operands of the Computer Hardware


/>
20

§2.3 Operands of the Computer Hardware

Register Operands


MIPS Register File
• Holds thirty-two 32-bit registers


• Two read ports and
• One write port
Registers are




Faster than main memory

src1 addr
src2 addr
dst addr

Register File
32 bits

5


32 src1

data

5

32
locations

5

32 src2

32

write data
- 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

data

write control

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)
Sep-16

CuuDuongThanCong.com

Representing Instructions in the Computer

/>
21


Bảng các thanh ghi MIPS
Register
Number

Name
$zero
$at
$v0 - $v1
$a0 - $a3
$t0 - $t7
$s0 - $s7
$t8 - $t9
$gp
$sp
$fp
$ra


0
1
2-3
4-7
8-15
16-23
24-25
28
29
30
31

Sep-16

CuuDuongThanCong.com

Preserve
on call?

Usage
constant 0 (hardware)
reserved for assembler
returned values
arguments
temporaries
saved values
temporaries
global pointer
stack pointer
frame pointer

return addr (hardware)

n.a.
n.a.
no
yes
no
yes
no
yes
yes
yes
yes

Operands of the Computer Hardware

/>
22


Register Operand Example

• Ví dụ: mã C của lệnh

f = (g + h) - (i + j);
• f, …, j in $s0, …, $s4

Sep-16

CuuDuongThanCong.com


Operands of the Computer Hardware

/>
23


Register Operand Example

• Biên dịch sang mã MIPS:
add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1
Sep-16

CuuDuongThanCong.com

Operands of the Computer Hardware

/>
24


Memory Operands
• Bộ nhớ chính được sử dụng cho dữ liệu hỗn hợp
• Arrays, structures, dynamic data

• Ứng dụng cho các phép toán số học
• Nạp dữ liệu từ bộ nhớ
• Lưu kết quả từ thanh ghi vào bộ nhớ


• Bộ nhớ được đánh địa chỉ theo byte
• Mỗi địa được xác định bởi 1 byte 8bit

• Các word được sắp xếp trong bộ nhớ
• Địa chỉ phải chia hết cho 4

• MIPS is Big Endian
• Bit cao là bit địa chỉ thấp của 1 từ
• c.f. Little Endian: Bit thấp là bit địa chỉ thấp của 1 từ

Sep-16

CuuDuongThanCong.com

Operands of the Computer Hardware

/>
25


×