chapter 10 instruction sets: characteristics and functions ...

40
Chapter 10 Instruction Sets: Characteristics and Functions คคคคคคคคคคคคคคคคคคค คคคคคคคคคคคคค 1.คคคคคคคคคคคคคคคคคคคคคคค คคคคคคค 2.คคคคคคคคคคคคคคคคคคคคคคค 3.คคคคคคคค คคคคคคคคคคคคคคค คคคคคคค Pentium คคค PowerPC 4.คคคคคคคคคคคคคคคคคคคคคค Pentium คคค PowerPC 5.คคคคคคคคคคคคค

Upload: rex

Post on 21-Mar-2016

78 views

Category:

Documents


11 download

DESCRIPTION

คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ ตัวอย่าง ชนิดของข้อมูลในเครื่อง Pentium และ PowerPC ชนิดการทำงานในเครื่อง Pentium และ PowerPC ภาษาแอสแซมบลี. Chapter 10 Instruction Sets: Characteristics and Functions คุณลักษณะและหน้าที่ของชุดคำสั่ง. What is an instruction set?. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Chapter 10Instruction Sets:Characteristicsand Functions คณลกษณะและหนาทของชดคำาสง

1 .คณลกษณะของคำาสงภาษาเครอง2 .ชนดของตวถกดำาเนนการ3 .ตวอยาง ชนดของขอมลในเครอง Pentium

และ PowerPC4 .ชนดการทำางานในเครอง Pentium และ

PowerPC5 .ภาษาแอสแซมบล

Page 2: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

What is an instruction set?• The complete collection of instructions

that are understood by a CPU• Machine Code• Binary• Usually represented by assembly codes

สรปการทำางานของ CPU ถกกำาหนดโดยคำาสงทกำาลงทำาการประมวลผลอยในขณะนน ซงเรยกวา คำาสงเครอง คำาสงเครองเมอนำามารวมเขาไวดวยกน หรอเมออางกลมคำาสงสำาหรบคอมพวเตอร เรยกวา “ชดคำาสง”

Page 3: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Elements of an Instruction(องคประกอบของชดคำาสง)• Operation code (Op code)

—บอกใหทราบถงงานททำา เชนการบวก หรองาน I/O • Source Operand reference

—แหลงอางองแหลงทมาขอมล การทำางานอาจจะมการอางองถงตวถกดำาเนนการ หรอทบอกแหลงทเกบขอมลทตองนำามาใช

ในการกระทำานน• Result Operand reference

—การอางองแหลงทเกบขอมลเมอมการดำาเนนการ พดงายๆ คอทเกบผลลพธของการทำางาน

• Next Instruction Reference—การอางองคำาสงถดไป เปนการบอกให CPU ทราบตำาแหนงถด

ไปทจะทำางาน

Page 4: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Where have all the Operands gone?(ตวถกดำาเนนการทใชบอกตำาแหนงการอางองแหลงทมาหรอทเกบขอมล อาจจอยในรปแบบน

• Main memory (or virtual memory or cache) หนวยความจำาหลกหรอหนวยความจำาเสมอน

• CPU register ตำาแหนงของการอางองหรอทเกบขอมลคอ Register ทอยภายในตว CPU เอง เชน Ld a,01h

• I/O device ตำาแหนงของอปกรณทใชเกบขอมล หรอแสดงผลลพธของขอมล

Page 5: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Instruction Cycle State Diagram

Page 6: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Instruction Representation• In machine code each instruction has a

unique bit pattern(ใน Computer แตละชดคำาสงจะเรยงกนในรปแบบของ Bit Binary)

• For human consumption (well, programmers anyway) a symbolic representation is used (การทจะอธบายรายละเอยดโดยเลขฐาน 2 นน เปนเรองยากดงนนจงไดเลอกภาษาสญลกษณทงายตอการเขาใจ เชน—e.g. ADD, SUB, LOAD

• Operands can also be represented in this way (ตวถกดำาเนนการกใชคำายอเหมอนกน)—ADD A,B

Page 7: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Simple Instruction Format(รปแบบคำาสงแบบงาย)

Page 8: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Instruction Types

• Data processing คำาสงในการประมวลผลขอมลทางคณตศาสตร

• Data storage (main memory) คำาสงเกยวกบหนวยความจำา

• Data movement (I/O) คำาสงเกยวกบการ I/O• Program flow control คำาสงควบคมลำาดบการ

ประมวลผล

คอมพวเตอรควรมชดคำาสงทชวยใหผใชสามารถประมวลผลงานทตองการได ดงนนชดคำาสงจะตองมมากพอ ทจะใชแปลความหมายภาษา

ระดบสงโดยมากภาษาเครองจงถกแบงเปนประเภทตางๆ ดงน)

Page 9: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

เปรยบเทยบคำสงทใชทอยององ Y=(A-B)/(C+D*E)Instruction CommentSUB Y , A, B

YA – BMPY T, D, E

TD EADD T, T, C TT + CDIV Y, Y, T

YY T(a)Three-address

instructionsMOVE Y, A

YASUB Y, B

YY – BMOVE T, D

TDMPY T, E

TT EADD T, C TT + CDIV Y, T

YY T(b) Two-address

instructions

InstructionComment

LOAD D ACDMPY E ACAC EADDC ACAC + CSTOR Y YACLOAD A ACASUB B ACAC –

BDIV Y ACAC

YSTOR Y YAC(c) One-address

instructions

Page 10: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Number of Addresses (a) จำานวนของทอยอางองในคำาสงเครอง• 3 addresses

—Operand 1, Operand 2, Result—a = b + c;—May be a forth - next instruction (usually

implicit)—Not common—Needs very long words to hold everything

Page 11: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Number of Addresses (b)• 2 addresses

—One address doubles as operand and result—a = a + b—Reduces length of instruction—Requires some extra work

– Temporary storage to hold some results

Page 12: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Number of Addresses (c)• 1 address

—Implicit second address—Usually a register (accumulator)—Common on early machines

Page 13: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Number of Addresses (d)• 0 (zero) addresses

—All addresses implicit—Uses a stack—e.g. push a— push b— add— pop c

—c = a + b

Page 14: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

How Many Addresses• More addresses ถาใช Address มาก

—More complex (powerful?) instructions (ซบซอน)—More registers (ใช Register มากกวา)

– Inter-register operations are quicker—Fewer instructions per program (ใชชดคำาสงนอยตอ

โปรแกรม)• Fewer addresses ถาใช Address นอย

—Less complex (powerful?) instructions (ซบซอนนอยกวา)

—More instructions per program(ใชชดคำาสงมากกวาตอโปรแกรม)

—Faster fetch/execution of instructions (ประมวลผลเรวกวา)

Page 15: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Design Decisions (1) (การออกแบบชดคำาสงมปจจยไรบาง)• ชดคำาสงจะเปนตวกำาหนดหนาทการทำางานของ CPU จงมผล

โดยตรงตอการออกแบบและสราง CPU ขนมาใชงานและเปนเสมอนเครองมอของ Programmer ทใชควบคมการทำางานของ CPU ดงนนความตองการของ Programmer จะตองถกนำามาใชรวมพจารณาในระหวางออกแบบชดคำาสง

• Operation repertoire—How many ops? CPU ควรจะมฟงกชนการทำางานเปนเทาใด —What can they do? การทำางานแตละอยางควรทำาอะไร—How complex are they? การทำางานมความซบซอนมากเพยงใด

• Data types ชนดของขอมลทนำามาใช• Instruction formats ความยาวของคำาสง

—Length of op code field ความยาวของคำาสง—Number of addresses จำานวนของแอดเดรส

Page 16: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Design Decisions (2)• Registers

—Number of CPU registers available จำานวน Register

—Which operations can be performed on which registers?

• Addressing modes (later…) รปแบบการทำางานทใชกำาหนดชนดของทอยของตวถกดำาเนนการ

• RISC v CISC

Page 17: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Types of Operand ชนดของตวถกดำาเนนการ• Addresses ตำาแหนงทอย• Numbers ตวเลข

—Integer/floating point• Characters ตวอกษร

—ASCII etc.• Logical Data ขอมลตรรกะ

—Bits or flags• (Aside: Is there any difference between numbers and

characters? Ask a C programmer!)

Page 18: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Pentium Data Types• 8 bit Byte• 16 bit word• 32 bit double word• 64 bit quad word• Addressing is by 8 bit unit• A 32 bit double word is read at addresses

divisible by 4

Page 19: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Specific Data Types(ชนดขอมลของ Pentium)• General - arbitrary binary contents• Integer - single binary value• Ordinal - unsigned integer• Unpacked BCD - One digit per byte• Packed BCD - 2 BCD digits per byte• Near Pointer - 32 bit offset within segment• Bit field• Byte String• Floating Point

Page 20: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Pentium Floating Point Data Types

Page 21: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

PowerPC Data Types (ชนดขอมลใน cpu Power PC)• 8 (byte), 16 (halfword), 32 (word) and 64

(doubleword) length data types• Some instructions need operand aligned

on 32 bit boundary• Can be big- or little-endian• Fixed point processor recognises:

—Unsigned byte, unsigned halfword, signed halfword, unsigned word, signed word, unsigned doubleword, byte string (<128 bytes)

• Floating point—IEEE 754—Single or double precision

Page 22: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Types of Operation (ชนดของ Opcode)• Data Transfer การเคลอนยายขอมล• Arithmetic การคำานวณทางคณตศาสตร• Logical การคำานวณตรรกะ• Conversion การเปลยนรปขอมล• I/O คำาสง I/O• System Control การควบคมระบบ• Transfer of Control การถายโอนการควบคมการ

ประมวลผล

Page 23: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Data Transfer ในการเคลอนยายจะตองกำาหนดการทำางานซงมองคประกอบดงน

• Specify—Source บอกตำาแหนงของขอมล—Destination บอกตำาแหนงสำาหรบบนทกผลลพธ—Amount of data กำาหนดความยาวของขอมลทเคลอนยาย

• May be different instructions for different movements จะใชชดคำาสงทแตกตางกนในการเคลอนยายขอมลแตละแบบ เชน Reg – Reg หรอ Mem - Mem—e.g. IBM 370

• Or one instruction and different addresses —e.g. VAX คอ VaX จะใชคำาสง Mov คำาสงเดยวในการเคลอนยายขอมลหลายขนาด จงงายในการพฒนาโปรแกรม

Page 24: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Arithmetic(การคำานวณทางคณตศาสตร)

• Computer สวนใหญจะจดใหมคำาสงสำาหรบการคำานวณพนฐานไดแก- Add, Subtract, Multiply, Divide

• Signed Integer• Floating point ?• May include

—Increment (a++)—Decrement (a--)—Negate (-a)

Page 25: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Logical (การคำานวณทางตรรกะ)• คำาสงสำาหรบการจดการขอมลแตละบต• Bitwise operations• AND, OR, NOT• นอกเหนอจากการทำางานกบบตแลวยงจดเตรยมฟงกชน

ในการ shift และ Rotate ดงน

Page 26: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Shift and Rotate Operations

Page 27: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Conversion (การเปลยนรปขอมล)• หมายถงคำาสงทเปลยนรปแบบ หรอคำาสงทำางานกบรป

แบบของขอมลเชน• E.g. Binary to Decimal (คำาสงการเปลยนเลขฐาน

สองเปนฐานสบ)

Page 28: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Input/Output (คำาสงทตดตอกบอปกรณ Input/Output)• May be specific instructions• May be done using data movement

instructions (memory mapped)• May be done by a separate controller

(DMA)

Page 29: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Systems Control(คำาสงสำาหรบการควบคมระบบ)• หมายถงคำาสงทสามารถควบคมระบบการทำางานของ

CPU ได โดยทวไปจะถกสวงนไวในระบบปฏบตการ

• Privileged instructions เปนชดคำาสงพเศษ

Page 30: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Transfer of Control (คำาสงการถายโอนการควบคมการประมวลผล)• หมายถงคำาสงทควบคมการทำางานลำาดบของการประมวล

ผลนนเอง(เปลยนลำาดบการประมวลผล ) เชน• Branch เงอนไขกระโดดเมอเปนไปตามเงอนไข

—e.g. branch to x if result is zero• Skip จะขามคำาสงในลำาดบถดไป

—e.g. increment and skip if zero—ISZ Register1—Branch xxxx—ADD A

• Subroutine call การเรยกใชฟงกชน—c.f. interrupt call

Page 31: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Branch Instruction

Page 32: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Nested Procedure Calls

Page 33: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Use of Stack

Page 34: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

สรปตวอยงชนดของ OpcodeType Operation

NameDescription

Data transfer

Move (transfer)StoreLoad (fetch)ExchangeClear (reset)SetPushPop

Transfer word or block from source to destinationTransfer word from processor to memoryTransfer word from memory to processorSwap contents of source and destinationTransfer word of 0s to destinationTransfer word of 1s to destinationTransfer word from source to top of stackTransfer word from top of stack to destination

Arithmetic

AddSubtractMultiplyDivideAbsoluteNegateIncrementDecrement

Compute sum of two operandsCompute difference of two operandsCompute product of two operandsCompute quotient of two operandsReplace operand by its absolute valueChange sign of operandAdd 1 to operandSubtract 1 from operand

Page 35: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

สรปตวอยงชนดของ Opcode

Logical

ANDORNOT (Complement)Exclusive-OR

TestCompareSet control variablesShiftRotate

Perform the specified logical operation bitwise

Test specified condition; set flag(s) based on outcomeMake logical or arithmetic comparison of two or more operands; set flag(s) based on outcomeClass of instructions to set controls for protection purposes,interrupt handling, timer control, etc.Left (right) shift operand, introducing constants at endLeft (right) shift operand, with wraparound end

Page 36: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

สรปตวอยงชนดของ Opcode

TransferOf control

Jump (branch)Jump conditional

Jump to subroutine

Return

Execute

SkipSkip conditionalHaltWait (hold)

No operation

Unconditional transfer; load PC with specified addressTest specified condition; either load PC with specified address or do nothing, based on conditionPlace current program control information in known location; jump to specified addressReplace contents of PC and other register from known locationFetch operand from specified location and execute as instruction; do not modify PCIncrement PC to skip next instructionTest specified condition; either skip or do nothing based on conditionStop program executionStop program execution; test specified condition repeatedly: resume execution when condition is satisfiedNo operation is performed, but program execution is continued

Page 37: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

สรปตวอยงชนดของ Opcode

Input/output

Input (read)

Output (write)

Start I/O

Test I/O

Transfer data from specified I/O port or device to destination(e.g., main memory or processor register)Transfer data from specified source to I/O port or deviceTransfer instructions to I/O processor to initiate I/O operationTransfer status information from I/O system to specified destination

conversion

Translate

Convert

Translate values in a section of memory based on a table of correspondencesConvert the contents of a word from one form to another (e.g., packed decimal to binary)

Page 38: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Byte Order ลำาดบของ Byte• ขอมลใน byte ตางๆ มวธการจดเรยงยงไง โดยทวไปวธ

การจดเรยงจะมดงนคอ— Little Endian— Big Endian

• ตวอยาง มขอมลขนาด 32 Bit (Hex) คอ 12345678 ซงถกเกบในหนวยความจำาทตำาแหนง 184 ในเครองคอมพวเตอร ลกษณะการเกบขอมลสามารถเกบไดสองวธคอ

Page 39: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Byte Order (example)• Address Value (1) Value(2)• 184 12 78• 185 34 56• 186 56 34• 186 78 12 Big Endian Little Endian

Page 40: Chapter 10 Instruction Sets: Characteristics and Functions   คุณลักษณะและหน้าที่ของชุดคำสั่ง

Standard…What Standard?• Pentium (80x86), VAX are little-endian• IBM 370, Moterola 680x0 (Mac), and most

RISC are big-endian• Internet is big-endian

—Makes writing Internet programs on PC more awkward!

—WinSock provides htoi and itoh (Host to Internet & Internet to Host) functions to convert