1. Trang chủ
  2. » Tất cả

kiến trúc máy tính phạm minh cường chương ter2 part1 instructions language of the computer [sinhvienzone.com]

27 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 27
Dung lượng 1,1 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Instruction Execution• Instruction fetch: from the memory – PC increased – PC stores the next instruction • Execution: decode and executeSinhVienZone.com... Data Transfer Instructions• M

Trang 1

Computer Architecture

Chapter 2: MIPS

Dr Phạm Quốc Cường

SinhVienZone.com

Trang 2

Language: a system of communication consisting of sounds, words, and grammar,

or the system of communication used by people in a particular country or type of work (Oxford Dictionary)

SinhVienZone.com

Trang 3

Introduction (cont.)

• To command a computer’s hardware: speak its

language

SinhVienZone.com

Trang 4

Instruction Set Architecture (ISA)

SinhVienZone.com

Trang 5

Von Neumann Architecture

Trang 6

Computer Components

SinhVienZone.com

Trang 7

Instruction Execution

• Instruction fetch: from the memory

– PC increased

– PC stores the next instruction

• Execution: decode and executeSinhVienZone.com

Trang 8

The MIPS Instruction Set

Trang 9

IS Design Principles

• Simplicity favors regularity

• Smaller is faster

• Make the common case fast

• Good design demands good compromises

SinhVienZone.com

Trang 11

Source register 2(*)

SinhVienZone.com

Trang 12

Design Principle 1

• Simplicity favours regularity

– Regularity makes implementation simpler

– Simplicity enables higher performance at lower cost

SinhVienZone.com

Trang 13

Arithmetic Instructions: Example

• Q: what is MIPS code for the following C code

SinhVienZone.com

Trang 14

Data Transfer Instructions

• Move data b/w memory

and registers

– Register

– Address: a value used to

delineate the location of

a specific data element

within a memory array

• Load: copy data from

memory to a register

• Store: copy data from a

register to memory

SinhVienZone.com

Trang 15

Data Transfer Instructions (cont.)

• Memory address: offset(base register)

– Byte address: each address identifies an 8-bit byte– “words” are aligned in memory (address must be multiple of 4)

Opcode Register Memory

address

SinhVienZone.com

Trang 16

Data Transfer Instructions (cont.)

Trang 17

Memory Operands

• Main memory used for composite data

– Arrays, structures, dynamic data

• To apply arithmetic operations

– Load values from memory into registers

– Store result from register to memory

• MIPS is Big Endian

– Most-significant byte at least address of a word

– c.f Little Endian: least-significant byte at least address

SinhVienZone.com

Trang 18

Memory Operand Example 1

• C code:

g = h + A[8];

– g in $s1, h in $s2, base address of A in $s3

• Compiled MIPS code:

– Index 8 requires offset of 32

• 4 bytes per word

lw $t0, 32($s3) # load word

add $s1, $s2, $t0SinhVienZone.com

Trang 19

Memory Operand Example 2

• C code:

A[12] = h + A[8];

– h in $s2, base address of A in $s3

• Compiled MIPS code:

– Index 8 requires offset of 32

lw $t0, 32($s3) # load word

add $t0, $s2, $t0

sw $t0, 48($s3) # store wordSinhVienZone.com

Trang 20

Registers vs Memory

• Registers are faster to access than memory

• Operating on memory data requires loads and stores

– More instructions to be executed

• Compiler must use registers for variables as

Trang 21

Immediate Operands

• Constant data specified in an instruction

addi $s3, $s3, 4

• No subtract immediate instruction

– Just use a negative constant

addi $s2, $s1, -1

• Design Principle 3: Make the common case

fast

– Small constants are common

– Immediate operand avoids a load instruction

SinhVienZone.com

Trang 22

The Constant Zero

• MIPS register 0 ($zero) is the constant 0

– Cannot be overwritten

• Useful for common operations

– E.g., move between registers

add $t2, $s1, $zero

SinhVienZone.com

Trang 23

Unsigned Binary Integers

• Given an n-bit number

1 1

2 n 2 n

1 n 1

Trang 24

2s-Complement Signed Integers

• Given an n-bit number

1 1

2 n 2 n

1 n 1

Trang 25

2s-Complement Signed Integers

• Bit 31 is sign bit

– 1 for negative numbers

– 0 for non-negative numbers

Trang 26

11111 111

Trang 27

Sign Extension

• Representing a number using more bits

– Preserve the numeric value

• In MIPS instruction set

– addi: extend immediate value

– lb, lh: extend loaded byte/halfword

– beq, bne: extend the displacement

• Replicate the sign bit to the left

– c.f unsigned values: extend with 0s

• Examples: 8-bit to 16-bit

– +2: 0 000 0010 => 0000 0000 0 000 0010

– –2: 1 111 1110 => 1111 1111 1 111 1110

SinhVienZone.com

Ngày đăng: 30/01/2020, 20:12

🧩 Sản phẩm bạn có thể quan tâm