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

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

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

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


งานนำเสนอเรื่อง: "2.2 ภาษาเครื่อง (Machine language)"— ใบสำเนางานนำเสนอ:

1 2.2 ภาษาเครื่อง (Machine language)
จากรูป แสดงลำดับของเลข 0 และ 1 นำไปใช้งานโดย CPU เป็นคำสั่ง Load ข้อมูล และ Mnemonic form ที่ใช้แทนคำสั่งดังกล่าวนี้ 13/06/47 Machine Structure, Machine Language, and Assembly Language

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

3 Machine Structure, Machine Language, and Assembly Language
13/06/47 Machine Structure, Machine Language, and Assembly Language

4 Machine Structure, Machine Language, and Assembly Language
13/06/47 Machine Structure, Machine Language, and Assembly Language

5 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions : 948 952 956 960 964 968 972 976 980 984 988 900 904 908 912 916 920 924 928 932 936 940 C A F 49 5 7 9 12 8 10 15 16 3 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

6 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions : 948 952 956 960 964 968 972 976 980 984 988 900 904 908 912 916 920 924 928 932 936 940 C A F 49 54 7 9 12 8 10 15 16 3 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

7 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions : 948 952 956 960 964 968 972 976 980 984 988 900 904 908 912 916 920 924 928 932 936 940 C A F 49 54 56 9 12 8 10 15 16 3 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

8 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions 48 52 56 : 948 952 956 960 964 968 972 976 980 984 988 4 8 900 904 908 912 916 920 924 928 932 936 940 5A201384 C A F L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) 49 5 7 9 12 10 15 16 3 13/06/47 Machine Structure, Machine Language, and Assembly Language

9 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions 48 52 56 : 948 952 956 960 964 968 972 976 980 984 988 4 8 900 904 908 912 916 920 924 928 932 936 940 5A201384 C A F L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) 49 54 7 9 12 10 15 16 3 13/06/47 Machine Structure, Machine Language, and Assembly Language

10 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions 48 52 56 60 64 68 : 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 900 904 908 912 916 920 924 928 932 936 940 5A201384 C C C A F L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,908(0,1) ST 2,908(0,1) 49 54 7 9 10 15 3 13/06/47 Machine Structure, Machine Language, and Assembly Language

11 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Hexa Decimal Instructions 48 52 56 60 64 68 : 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 900 904 908 912 916 920 924 928 932 936 940 5A201384 C C C A F L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,908(0,1) ST 2,908(0,1) 49 54 9 10 15 3 13/06/47 Machine Structure, Machine Language, and Assembly Language

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

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

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

15 2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล
2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล สมมติว่า มีนักศึกษาของ MIT คนหนึ่งต้องการออกเดทกับหญิงสาว ขั้นตอนการออกเดทของเขา อาจจะเขียนเป็นโปรแกรมได้ดังนี้ 1 2 3 4 5 เช่าสูท เหน็บ Slide rule โทรหา Nancy ถ้าถูกปฏิเสธ เปลี่ยน 3 เป็น Marry กลับไปทำ 1 13/06/47 Machine Structure, Machine Language, and Assembly Language

16 2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล (ต่อ)
2.2.2 การเปลี่ยนค่าแอดเดรส โดยการใช้คำสั่งเสมือนเป็นข้อมูล (ต่อ) สมมติว่า มีนักศึกษาของ MIT คนหนึ่งต้องการออกเดทกับหญิงสาว ขั้นตอนการออกเดทของเขา อาจจะเขียนเป็นโปรแกรมได้ดังนี้ 1 2 3 4 5 เช่าสูท เหน็บ Slide rule โทรหา Marry ถ้าถูกปฏิเสธ เปลี่ยน 3 เป็น Jane กลับไปทำ 1 13/06/47 Machine Structure, Machine Language, and Assembly Language

17 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 5 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

18 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 5 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

19 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

20 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,904(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

21 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,908(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

22 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,908(0,1) A 2,900(0,1) ST 2,904(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

23 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,908(0,1) A 2,900(0,1) ST 2,908(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 7 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

24 Machine Structure, Machine Language, and Assembly Language
Absolute address Relative Address Instructions Comments 48 52 56 60 64 68 72 76 80 : 944 948 952 956 960 964 968 972 976 980 984 988 4 8 12 16 20 24 28 32 896 900 904 908 912 916 920 924 928 932 936 940 L 2,908(0,1) A 2,900(0,1) ST 2,908(0,1) L 2,0 (0,1) A 2,896(0,1) ST 2,0 (0,1) L 2,8 (0,1) ST 2,8 (0,1) Branch to 0 49 54 9 10 15 3 บวก 49 ให้กับ 904 เพิ่ม Load อีก 4 เพิ่ม Store อีก 4 13/06/47 Machine Structure, Machine Language, and Assembly Language

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

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


ดาวน์โหลด ppt 2.2 ภาษาเครื่อง (Machine language)

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


Ads by Google