1 / 40

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

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

rex
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

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

  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

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

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

  9. เปรียบเทียบคำสั่งที่ใช้ที่อยู่อ้างอิง Y=(A-B)/(C+D*E)

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

  11. 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

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

  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

  14. 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 (ประมวลผลเร็วกว่า)

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

  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

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

  18. 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

  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

  20. Pentium Floating Point Data Types

  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 การถ่ายโอนการควบคุมการประมวลผล

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

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

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

  26. Shift and Rotate Operations

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

  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)

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

  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

  31. Branch Instruction

  32. Nested Procedure Calls

  33. Use of Stack

  34. สรุปตัวอย่างชนิดของ Opcode

  35. สรุปตัวอย่างชนิดของ Opcode

  36. สรุปตัวอย่างชนิดของ Opcode

  37. สรุปตัวอย่างชนิดของ Opcode

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

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

  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

More Related