1 / 26

2.2 ภาษาเครื่อง (Machine language)

2.2 ภาษาเครื่อง (Machine language). จากรูป แสดงลำดับของเลข 0 และ 1 นำไปใช้งานโดย CPU เป็นคำสั่ง Load ข้อมูล และ Mnemonic form ที่ใช้แทนคำสั่งดังกล่าวนี้. ตัวอย่าง. จงเขียนโปรแกรม ที่บวกตัวเลข 49 กับข้อมูลแบบ Fullword ที่เก็บเรียงแถวติดกัน 10 ตัว โดยอยู่ภายใต้ข้อสมมุติฐานต่อไปนี้

Télécharger la présentation

2.2 ภาษาเครื่อง (Machine language)

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. 2.2 ภาษาเครื่อง (Machine language) จากรูป แสดงลำดับของเลข 0 และ 1 นำไปใช้งานโดย CPU เป็นคำสั่ง Load ข้อมูล และ Mnemonic form ที่ใช้แทนคำสั่งดังกล่าวนี้ Machine Structure, Machine Language, and Assembly Language

  2. ตัวอย่าง จงเขียนโปรแกรม ที่บวกตัวเลข 49 กับข้อมูลแบบ Fullword ที่เก็บเรียงแถวติดกัน 10 ตัว โดยอยู่ภายใต้ข้อสมมุติฐานต่อไปนี้ • ข้อสมมุติฐานที่ 1: เลข 10 จำนวน ที่จะนำมาบวก เป็นแบบ Fullword เรียงติดกัน มีแอดเดรสเริ่มต้นแบบ Absolute ที่ 952 • ข้อสมมุติฐานที่ 2: โปรแกรมอยู่ในหน่วยความจำ เริ่มต้นที่แอดเดรส 48 • ข้อสมมุติฐานที่ 3: เลข 49 เป็นข้อมูลแบบ Fullword อยู่ที่ Absolute แอดเดรส 948 • ข้อสมมุติฐานที่ 4: รีจิสเตอร์ 1 บรรจุข้อมูล 48 Machine Structure, Machine Language, and Assembly Language

  3. Machine Structure, Machine Language, and Assembly Language

  4. Machine Structure, Machine Language, and Assembly Language

  5. Machine Structure, Machine Language, and Assembly Language

  6. Machine Structure, Machine Language, and Assembly Language

  7. Machine Structure, Machine Language, and Assembly Language

  8. Machine Structure, Machine Language, and Assembly Language

  9. Machine Structure, Machine Language, and Assembly Language

  10. Machine Structure, Machine Language, and Assembly Language

  11. Machine Structure, Machine Language, and Assembly Language

  12. 2.2.1 หนทางยาวไกล ไม่มีลูปวนซ้ำ (Long Way, No Looping) ปัญหาของโปรแกรมที่แล้ว 1) ถ้าเราต้องการโปรเซสข้อมูล 300 ตัว (แทนที่จะเป็น 10 ตัว เหมือนครั้งแรก) • ที่เก็บสำหรับคำสั่ง จะเป็น (3 คำสั่ง) x (ความยาวของแต่ละคำสั่ง) x (จำนวนข้อมูลทั้งหมด) = 3,600 ไบท์ • ดังนั้น คำสั่งก็จะ ทับข้อมูลของเราในหน่วยความจำ Machine Structure, Machine Language, and Assembly Language

  13. ปัญหาของโปรแกรมที่แล้ว (ต่อ) 2) ระยะทางจาก คำสั่งแรก จนถึงข้อมูลตัวสุดท้าย ควรจะเป็น 4,800 ไบท์ แต่เนื่องจาก ข้อมูลมันเอง กินพื้นที่ 4 x 300 = 1,200 ไบท์ การใช้รีจิสเตอร์ เป็น Base รีจิสเตอร์ จึงเป็นไปไม่ได้ที่จะ Access ข้อมูล ตั้งแต่หัวถึงท้ายพร้อมกัน ถ้าเขียนภาษาเครื่อง และจะต้องนึกอยู่เสมอว่าตัวเลขที่มากที่สุด ที่เป็นไปได้คือ 212-1 หรือ 4,095 ซึ่งอาจไม่สามารถ Access ข้อมูลได้ทั่วถึงทั้งหมดพร้อมกัน Machine Structure, Machine Language, and Assembly Language

  14. Relocation ถ้าโปรแกรมก่อนหน้านี้ ถูก Load ไปไว้ที่แอดเดรส 336 (แทนที่จะเป็นแอดเดรส 48 เหมือนก่อนหน้า) มันยังคงทำงานได้อย่างถูกต้อง ถ้าค่าในรีจิสเตอร์ 1 ถูกเปลี่ยนให้เป็น 336 การย้ายโปรแกรมไปยังตำแหน่งต่างๆ ในหน่วยความจำ เรียกว่า การ Relocation โดยปกติ Base รีจิสเตอร์ จะถูกใช้ในการ Relocation นี้ Machine Structure, Machine Language, and Assembly Language

  15. 2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล สมมติว่า มีนักศึกษาของ MIT คนหนึ่งต้องการออกเดทกับหญิงสาว ขั้นตอนการออกเดทของเขา อาจจะเขียนเป็นโปรแกรมได้ดังนี้ Machine Structure, Machine Language, and Assembly Language

  16. สมมติว่า มีนักศึกษาของ MIT คนหนึ่งต้องการออกเดทกับหญิงสาว ขั้นตอนการออกเดทของเขา อาจจะเขียนเป็นโปรแกรมได้ดังนี้ 2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล (ต่อ) Machine Structure, Machine Language, and Assembly Language

  17. Machine Structure, Machine Language, and Assembly Language

  18. Machine Structure, Machine Language, and Assembly Language

  19. Machine Structure, Machine Language, and Assembly Language

  20. Machine Structure, Machine Language, and Assembly Language

  21. Machine Structure, Machine Language, and Assembly Language

  22. Machine Structure, Machine Language, and Assembly Language

  23. Machine Structure, Machine Language, and Assembly Language

  24. Machine Structure, Machine Language, and Assembly Language

  25. แอดเดรส เปลี่ยนได้อย่างไร เพื่อที่จะดูการทำงานของโปรแกรม เราต้องนึกอยู่เสมอว่า ค่าที่บรรจุอยู่ในตำแหน่ง 48 (ดังรูปที่ 2.1 ไม่ใช่ L 2, 904(0,1) แต่มันเป็น Machine Structure, Machine Language, and Assembly Language

  26. ปัญหา • การใช้คำสั่งเป็นเสมือนข้อมูลไม่ใช่เทคนิคการเขียนโปแกรมที่ดี เพราะว่าในระยะยาว การแก้ไขบำรุงรักษา (Maintenance) โปรแกรมจะลำบาก มันจะยากต่อการทำความเข้าใจว่าเริ่มแรกเลย ผู้เขียนต้องการจะทำอะไร • ในกรณีของระบบ Multiprocessing (หลายงาน บนระบบที่มีโปรเซสเซอร์มากกว่า 1 ตัว ทำงานพร้อมกัน) มันจะขัดแย้งกับกับกฎของ โค้ดบริสุทธิ์ (Pure code) หรือที่เรียกว่า เข้าใหม่ได้หลายครั้ง (Re-entrant code) เป็นโค้ดที่ ไม่มีการแก้ไขตัวมันเอง Machine Structure, Machine Language, and Assembly Language

More Related