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

26
13/06/47 Machine Structure, Machin e Language, and Assembly Language 1 2.2 ภภภภภภภภภภภ (Machine language) จจจจจจ จจจจจจจจจจจจจจจจ 0 จจจ 1 จจจ จจจจจจจจจจจ CPU จจจจจจจจจจจ Load จจจจจจ จจจ Mnemonic form จจจจจจจจจ จจจจจจจจจจจจจจจจจจ

Upload: bruno-solomon

Post on 30-Dec-2015

54 views

Category:

Documents


0 download

DESCRIPTION

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

TRANSCRIPT

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

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

1

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

จากรู�ป แสดงลำ าด�บของเลำข 0 แลำะ 1 นำ าไปใช้�งานำโดย CPU เป�นำคำ าส��ง Load ข�อมู�ลำ แลำะ Mnemonic form ที่ �ใช้�แที่นำคำ าส��งด�งกลำ!าวนำ #

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

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

2

ตั�วอย!างจงเข ยนำโปรูแกรูมู ที่ �บวกตั�วเลำข 49 ก�บข�อมู�ลำแบบ Fullwor

d ที่ �เก%บเรู ยงแถวตั'ดก�นำ 10 ตั�ว โดยอย�!ภายใตั�ข�อสมูมู)ตั'ฐานำตั!อไปนำ #

• ข�อสมูมู)ตั'ฐานำที่ � 1: เลำข 10 จ านำวนำ ที่ �จะนำ ามูาบวก เป�นำแบบ Fullword เรู ยงตั'ดก�นำ มู แอดเดรูสเรู'�มูตั�นำแบบ Absolute ที่ � 952

• ข�อสมูมู)ตั'ฐานำที่ � 2: โปรูแกรูมูอย�!ในำหนำ!วยคำวามูจ า เรู'�มูตั�นำที่ �แอดเดรูส 48

• ข�อสมูมู)ตั'ฐานำที่ � 3: เลำข 49 เป�นำข�อมู�ลำแบบ Fullword อย�!ที่ � Absolute แอดเดรูส 948

• ข�อสมูมู)ตั'ฐานำที่ � 4: รู จ'สเตัอรู, 1 บรูรูจ)ข�อมู�ลำ 48

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

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

3

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

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

4

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

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

5

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

::::::::::::

948952956960964968972976980984988

::::::::::::

900904908912916920924928932936940

::::::::::::000000310000000500000007000000090000000C000000080000000A0000000F000001000000000300000004

::::::::::::4957912810151634

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

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

6

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

::::::::::::

948952956960964968972976980984988

::::::::::::

900904908912916920924928932936940

::::::::::::000000310000003600000007000000090000000C000000080000000A0000000F000001000000000300000004

::::::::::::49547912810151634

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

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

7

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

::::::::::::

948952956960964968972976980984988

::::::::::::

900904908912916920924928932936940

::::::::::::000000310000003600000038000000090000000C000000080000000A0000000F000001000000000300000004

::::::::::::495456912810151634

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

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

8

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

485256:::::::::

948952956960964968972976980984988

048:::::::::

900904908912916920924928932936940

582013885A2013845201388:::::::::000000310000000500000007000000090000000C000000080000000A0000000F000001000000000300000004

L 2,904(0,1)A 2,900(0,1)ST 2,904(0,1):::::::::4957912810151634

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

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

9

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

485256:::::::::

948952956960964968972976980984988

048:::::::::

900904908912916920924928932936940

582013885A2013845201388:::::::::000000310000003600000007000000090000000C000000080000000A0000000F000001000000000300000004

L 2,904(0,1)A 2,900(0,1)ST 2,904(0,1):::::::::49547912810151634

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

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

10

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

485256606468::::::

948952956960964968972976980984988

048

121620::::::

900904908912916920924928932936940

582013885A20138452013885820138C5A2013845020138C::::::000000310000003600000007000000090000000C000000080000000A0000000F000001000000000300000004

L 2,904(0,1)A 2,900(0,1)ST 2,904(0,1)L 2,908(0,1)A 2,900(0,1)ST 2,908(0,1)::::::49547912810151634

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

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

11

Absoluteaddress

RelativeAddress

HexaDecimal

Instructions

485256606468::::::

948952956960964968972976980984988

048

121620::::::

900904908912916920924928932936940

582013885A20138452013885820138C5A2013845020138C::::::000000310000003600000038000000090000000C000000080000000A0000000F000001000000000300000004

L 2,904(0,1)A 2,900(0,1)ST 2,904(0,1)L 2,908(0,1)A 2,900(0,1)ST 2,908(0,1)::::::495456912810151634

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

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 ไบที่, – ด�งนำ�#นำ คำ าส��งก%จะ ที่�บข�อมู�ลำของเรูาในำหนำ!วยคำวามูจ า

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

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

13

ป�ญหาของโปรื่แกรื่ม่ท��แล!ว(ต่�อ)

2) รูะยะที่างจาก คำ าส��งแรูก จนำถ/งข�อมู�ลำตั�วส)ดที่�าย คำวรูจะเป�นำ 4,800 ไบที่,

แตั!เนำ.�องจาก ข�อมู�ลำมู�นำเอง ก'นำพื้.#นำที่ � 4 x 300 = 1,200 ไบที่, การูใช้�รู จ'สเตัอรู, เป�นำ Base รู จ'สเตัอรู, จ/งเป�นำไปไมู!ได�ที่ �จะ Access ข�อมู�ลำ ตั�#งแตั!ห�วถ/งที่�ายพื้รู�อมูก�นำ

ถ�าเข ยนำภาษาเคำรู.�อง แลำะจะตั�องนำ/กอย�!เสมูอว!าตั�วเลำขที่ �มูากที่ �ส)ด ที่ �เป�นำไปได�คำ.อ 212-1 หรู.อ 4,095 ซ/�งอาจไมู!สามูารูถ Access ข�อมู�ลำได�ที่��วถ/งที่�#งหมูดพื้รู�อมูก�นำ

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

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

14

Relocation

ถ�าโปรูแกรูมูก!อนำหนำ�านำ # ถ�ก Load ไปไว�ที่ �แอดเดรูส 336 (แที่นำที่ �จะเป�นำแอดเดรูส 48 เหมู.อนำก!อนำหนำ�า) มู�นำย�งคำงที่ างานำได�อย!างถ�กตั�อง ถ�าคำ!าในำรู จ'สเตัอรู, 1 ถ�กเปลำ �ยนำให�เป�นำ 336 การูย�ายโปรูแกรูมูไปย�งตั าแหนำ!งตั!างๆ ในำหนำ!วยคำวามูจ า เรู ยกว!า การู Relocation โดยปกตั' Base รู จ'สเตัอรู, จะถ�กใช้�ในำการู Relocation นำ #

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

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

15

2.2.2 การื่เปล��ยนค�าแอดเดรื่สโดยการื่ใช้!ค�าส'�งเสม่�อนเป(นข!อม่�ล

สมูมูตั'ว!า มู นำ�กศึ/กษาของ MIT คำนำหนำ/�งตั�องการูออกเดที่ก�บหญิ'งสาว ข�#นำตัอนำการูออกเดที่ของเขา อาจจะเข ยนำเป�นำโปรูแกรูมูได�ด�งนำ #

1 2 3 4 5

เช้�าส�ท

เหน)บ Slide rule

โทรื่หา Nancy

ถ้!าถ้�กปฏิ-เสธ

เปล��ยน 3 เป(น

Marry

กล'บไปท�า1

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

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

16

2.2.2 การื่เปล��ยนค�าแอดเดรื่สโดยการื่ใช้!ค�าส'�งเสม่�อนเป(นข!อม่�ล (ตั!อ)

สมูมูตั'ว!า มู นำ�กศึ/กษาของ MIT คำนำหนำ/�งตั�องการูออกเดที่ก�บหญิ'งสาว ข�#นำตัอนำการูออกเดที่ของเขา อาจจะเข ยนำเป�นำโปรูแกรูมูได�ด�งนำ #

1 2 3 4 5

เช้�าส�ท

เหน)บ Slide rule

โทรื่หา Marry

ถ้!าถ้�กปฏิ-เสธ

เปล��ยน 3 เป(น

Jane

กล'บไปท�า1

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

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

17

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::44957912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

18

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::44957912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

19

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::449547912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

20

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::449547912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

21

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::449547912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

22

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::449547912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

23

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::449547912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

24

Absoluteaddress

RelativeAddress

Instructions Comments

485256606468727680

::

944948952956960964968972976980984988

048

121620242832

::

896900904908912916920924928932936940

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)A 2,896(0,1)ST 2,8 (0,1) Branch to 0

::4495456912810151634

บวก 49 ให!ก'บ 904

เพิ่-�ม่ Load อ�ก 4

เพิ่-�ม่ Store อ�ก 4

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

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

25

แอดเดรูส เปลำ �ยนำได�อย!างไรูเพื้.�อที่ �จะด�การูที่ างานำของโปรูแกรูมู เรูาตั�องนำ/กอย�!เสมูอว!า คำ!าที่ �บรูรูจ)

อย�!ในำตั าแหนำ!ง 48 (ด�งรู�ปที่ � 2.1 ไมู!ใช้! L 2, 904(0,1) แตั!มู�นำเป�นำ

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

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

26

ป5ญิหา• การูใช้�คำ าส��งเป�นำเสมู.อนำข�อมู�ลำไมู!ใช้!เที่คำนำ'คำการูเข ยนำโป

แกรูมูที่ �ด เพื้รูาะว!าในำรูะยะยาว การูแก�ไขบ ารู)งรู�กษา (Maintenance) โปรูแกรูมูจะลำ าบาก มู�นำจะยากตั!อการูที่ าคำวามูเข�าใจว!าเรู'�มูแรูกเลำย ผู้��เข ยนำตั�องการูจะที่ าอะไรู

• ในำกรูณี ของรูะบบ Multiprocessing (หลำายงานำ บนำรูะบบที่ �มู โปรูเซสเซอรู,มูากกว!า 1 ตั�ว ที่ างานำพื้รู�อมูก�นำ) มู�นำจะข�ดแย�งก�บก�บกฎของ โคำ�ดบรู'ส)ที่ธิ์': (Pure code) หรู.อที่ �เรู ยกว!า เข�าใหมู!ได�หลำายคำรู�#ง (Re-entrant code) เป�นำโคำ�ดที่ � ไมู!มู การูแก�ไขตั�วมู�นำเอง