งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ"— ใบสำเนางานนำเสนอ:

1 คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ
Chapter 10 Instruction Sets: Characteristics and Functions คุณลักษณะและหน้าที่ของชุดคำสั่ง คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ ตัวอย่าง ชนิดของข้อมูลในเครื่อง Pentium และ PowerPC ชนิดการทำงานในเครื่อง Pentium และ PowerPC ภาษาแอสแซมบลี

2 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 ถูกกำหนดโดยคำสั่งที่กำลังทำการประมวลผลอยู่ในขณะนั้น ซึ่งเรียกว่า คำสั่งเครื่อง คำสั่งเครื่องเมื่อนำมารวมเข้าไว้ด้วยกัน หรือเมื่ออ้างกลุ่มคำสั่งสำหรับคอมพิวเตอร์ เรียกว่า “ชุดคำสั่ง” 2

3 Elements of an Instruction(องค์ประกอบของชุดคำสั่ง)
Operation code (Op code) บอกให้ทราบถึงงานที่ทำ เช่นการบวก หรืองาน I/O Source Operand reference แหล่งอ้างอิงแหล่งที่มาข้อมูล การทำงานอาจจะมีการอ้างอิงถึงตัวถูกดำเนินการ หรือที่บอกแหล่งที่เก็บข้อมูลที่ต้องนำมาใช้ในการกระทำนั้น Result Operand reference การอ้างอิงแหล่งที่เก็บข้อมูลเมื่อมีการดำเนินการ พูดง่ายๆ คือที่เก็บผลลัพธ์ของการทำงาน Next Instruction Reference การอ้างอิงคำสั่งถัดไป เป็นการบอกให้ CPU ทราบตำแหน่งถัดไปที่จะทำงาน 3

4 I/O device ตำแหน่งของอุปกรณ์ที่ใช้เก็บข้อมูล หรือแสดงผลลัพธ์ของข้อมูล
Where have all the Operands gone?(ตัวถูกดำเนินการที่ใช้บอกตำแหน่งการอ้างอิงแหล่งที่มาหรือที่เก็บข้อมูล อาจจอยู่ในรูปแบบนี้ Main memory (or virtual memory or cache) หน่วยความจำหลักหรือหน่วยความจำเสมือน CPU register ตำแหน่งของการอ้างอิงหรือที่เก็บข้อมูลคือ Register ที่อยู่ภายในตัว CPU เอง เช่น Ld a,01h I/O device ตำแหน่งของอุปกรณ์ที่ใช้เก็บข้อมูล หรือแสดงผลลัพธ์ของข้อมูล 4

5 Instruction Cycle State Diagram

6 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 5

7 Simple Instruction Format(รูปแบบคำสั่งแบบง่าย)

8 Data processing คำสั่งในการประมวลผลข้อมูลทางคณิตศาสตร์
Instruction Types คอมพิวเตอร์ควรมีชุดคำสั่งที่ช่วยให้ผู้ใช้สามารถประมวลผลงานที่ต้องการได้ ดังนั้นชุดคำสั่งจะต้องมีมากพอ ที่จะใช้แปลความหมายภาษาระดับสูงโดยมากภาษาเครื่องจึงถูกแบ่งเป็นประเภทต่างๆ ดังนี้) Data processing คำสั่งในการประมวลผลข้อมูลทางคณิตศาสตร์ Data storage (main memory) คำสั่งเกี่ยวกับหน่วยความจำ Data movement (I/O) คำสั่งเกี่ยวกับการ I/O Program flow control คำสั่งควบคุมลำดับการประมวลผล 6

9 เปรียบเทียบคำสั่งที่ใช้ที่อยู่อ้างอิง Y=(A-B)/(C+D*E)
Instruction Comment SUB Y , A, B YA – B MPY T, D, E TD  E ADD T, T, C TT + C DIV Y, Y, T YY T (a)Three-address instructions MOVE Y, A YA SUB Y, B YY – B MOVE T, D TD MPY T, E TT  E ADD T, C TT + C DIV Y, T YY T (b) Two-address instructions LOAD D ACD MPY E ACAC  E ADD C ACAC + C STOR Y YAC LOAD A ACA SUB B ACAC – B DIV Y ACAC Y (c) One-address instructions 6

10 Number of Addresses (a) จำนวนของที่อยู่อ้างอิงในคำสั่งเครื่อง
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 7

11 Number of Addresses (b)
One address doubles as operand and result a = a + b Reduces length of instruction Requires some extra work Temporary storage to hold some results 8

12 Number of Addresses (c)
Implicit second address Usually a register (accumulator) Common on early machines 9

13 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 10

14 More addresses ถ้าใช้ Address มาก
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 (ประมวลผลเร็วกว่า) 11

15 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 จำนวนของแอดเดรส 12

16 Design Decisions (2) Registers
Number of CPU registers available จำนวน Register Which operations can be performed on which registers? Addressing modes (later…) รูปแบบการทำงานที่ใช้กำหนดชนิดของที่อยู่ของตัวถูกดำเนินการ RISC v CISC 13

17 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!) 14

18 Addressing is by 8 bit unit
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 15

19 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 16

20 Pentium Floating Point Data Types
17

21 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

22 Types of Operation (ชนิดของ Opcode)
Data Transfer การเคลื่อนย้ายข้อมูล Arithmetic การคำนวณทางคณิตศาสตร์ Logical การคำนวณตรรกะ Conversion การเปลี่ยนรูปข้อมูล I/O คำสั่ง I/O System Control การควบคุมระบบ Transfer of Control การถ่ายโอนการควบคุมการประมวลผล 18

23 Or one instruction and different addresses
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 คำสั่งเดียวในการเคลื่อนย้ายข้อมูลหลายขนาด จึงง่ายในการพัฒนาโปรแกรม 19

24 Arithmetic(การคำนวณทางคณิตศาสตร์)
Computer ส่วนใหญ่จะจัดใหมีคำสั่งสำหรับการคำนวณพื้นฐานได้แก่ - Add, Subtract, Multiply, Divide Signed Integer Floating point ? May include Increment (a++) Decrement (a--) Negate (-a) 20

25 Logical (การคำนวณทางตรรกะ)
คำสั่งสำหรับการจัดการข้อมูลแต่ละบิต Bitwise operations AND, OR, NOT นอกเหนือจากการทำงานกับบิตแล้วยังจัดเตรียมฟังก์ชั่นในการ shift และ Rotate ดังนี้ 21

26 Shift and Rotate Operations

27 Conversion (การเปลี่ยนรูปข้อมูล)
หมายถึงคำสั่งที่เปลี่ยนรูปแบบ หรือคำสั่งทำงานกับรูปแบบของข้อมูลเช่น E.g. Binary to Decimal (คำสั่งการเปลี่ยนเลขฐานสองเป็นฐานสิบ) 22

28 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) 23

29 Systems Control(คำสั่งสำหรับการควบคุมระบบ)
หมายถึงคำสั่งที่สามารถควบคุมระบบการทำงานของ CPU ได้ โดยทั่วไปจะถูกสวงนไว้ในระบบปฏิบัติการ Privileged instructions เป็นชุดคำสั่งพิเศษ 24

30 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 25

31 Branch Instruction

32 Nested Procedure Calls

33 Use of Stack

34 สรุปตัวอย่างชนิดของ Opcode
Type Operation Name Description Data transfer Move (transfer) Store Load (fetch) Exchange Clear (reset) Set Push Pop Transfer word or block from source to destination Transfer word from processor to memory Transfer word from memory to processor Swap contents of source and destination Transfer word of 0s to destination Transfer word of 1s to destination Transfer word from source to top of stack Transfer word from top of stack to destination Arithmetic Add Subtract Multiply Divide Absolute Negate Increment Decrement Compute sum of two operands Compute difference of two operands Compute product of two operands Compute quotient of two operands Replace operand by its absolute value Change sign of operand Add 1 to operand Subtract 1 from operand

35 สรุปตัวอย่างชนิดของ Opcode
Logical AND OR NOT (Complement) Exclusive-OR Test Compare Set control variables Shift Rotate Perform the specified logical operation bitwise Test specified condition; set flag(s) based on outcome Make logical or arithmetic comparison of two or more operands; set flag(s) based on outcome Class of instructions to set controls for protection purposes, interrupt handling, timer control, etc. Left (right) shift operand, introducing constants at end Left (right) shift operand, with wraparound end

36 สรุปตัวอย่างชนิดของ Opcode
Transfer Of control Jump (branch) Jump conditional Jump to subroutine Return Execute Skip Skip conditional Halt Wait (hold) No operation Unconditional transfer; load PC with specified address Test specified condition; either load PC with specified address or do nothing, based on condition Place current program control information in known location; jump to specified address Replace contents of PC and other register from known location Fetch operand from specified location and execute as instruction; do not modify PC Increment PC to skip next instruction Test specified condition; either skip or do nothing based on condition Stop program execution Stop program execution; test specified condition repeatedly: resume execution when condition is satisfied No operation is performed, but program execution is continued

37 สรุปตัวอย่างชนิดของ 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 device Transfer instructions to I/O processor to initiate I/O operation Transfer status information from I/O system to specified destination conversion Translate Convert Translate values in a section of memory based on a table of correspondences Convert the contents of a word from one form to another (e.g., packed decimal to binary)

38 Byte Order ลำดับของ Byte
Little Endian Big Endian ตัวอย่าง มีข้อมูลขนาด 32 Bit (Hex) คือ ซึ่งถูกเก็บในหน่วยความจำที่ตำแหน่ง 184 ในเครื่องคอมพิวเตอร์ ลักษณะการเก็บข้อมูลสามารถเก็บได้สองวิธีคือ 27

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

40 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 30


ดาวน์โหลด ppt คุณลักษณะของคำสั่งภาษาเครื่อง ชนิดของตัวถูกดำเนินการ

งานนำเสนอที่คล้ายกัน


Ads by Google