24
Introduction to Computer organization & Assembly Language ธธธธธธธธ ธธธธธธธธธธธธ [email protected]

Introduction to Computer organization & Assembly Language

Embed Size (px)

DESCRIPTION

Introduction to Computer organization & Assembly Language. ธนาวินท์ รักธรรมานนท์ [email protected]. คอมพิวเตอร์. Hardware. Software. ความสัมพันธ์ของ Hardware และ Software. USER. ซอฟต์แวร์ประยุกต์. ซอฟต์แวร์ประยุกต์. System Library. System Library. ซอฟต์แวร์ระบบ. เครื่องคอมพิวเตอร์. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to Computer organization  & Assembly Language

Introduction toComputer organization & Assembly Language

ธนาวิ�นท์� รักธรัรัมานนท์�[email protected]

Page 2: Introduction to Computer organization  & Assembly Language

Hardware

Software

คอมพิ�วเตอร์

Page 3: Introduction to Computer organization  & Assembly Language

ความสั มพิ นธ์ของ Hardware และ Software

USER

เครั��องคอมพิ�วิเตอรั�ซอฟต�แวิรั�รัะบบ

System Library

ซอฟต�แวิรั�ปรัะยุ�กต� System

Library

ซอฟต�แวิรั�ปรัะยุ�กต�

Page 4: Introduction to Computer organization  & Assembly Language

CPU

MainMemory

HD

Computer ComponentsSecondary Memory

Input Devices

Output Devices

Page 5: Introduction to Computer organization  & Assembly Language

การ์ทำ�างานของเคร์��องคอมพิ�วเตอร์ ชุ�ดค�าสั่�งและข้#อม$ลจะถู$กเก'บอยุ$(ในหน(วิยุควิามจ�า CPU (microprocessor)ด+งข้#อม$ลและชุ�ดค�าสั่�งมา

จาก• หน(วิยุควิามจ�า• อ�ปกรัณ์�อ�นพิ�ต (Keyboard , Mouse , etc.)

CPU ปรัะมวิลผลข้#อม$ล CPU น�าข้#อม$ลผลลพิธ�ท์.�ถู$กปรัะมวิลผลแล#วิไปยุง

• หน(วิยุควิามจ�า• อ�ปกรัณ์�เอาท์�พิ�ต (Monitor , Printer , etc.)

Page 6: Introduction to Computer organization  & Assembly Language

โปร์แกร์มคอมพิ�วเตอร์ เรัาไม(สั่ามารัถูท์�างานต(างๆได# โดยุอาศัยุเพิ.ยุงแต(เครั��อง

คอมพิ�วิเตอรั�อยุ(างเด.ยุวิ เครั��องคอมพิ�วิเตอรั�สั่ามารัถูท์�างานได#รัวิดเรั'วิ แต(ไม(สั่ามารัถูท์.�จะ

ตดสั่�นใจหรั�อแก#ป3ญหาใดๆได#ด#วิยุล�าพิง มน�ษยุ�จะต#องเป6นผ$#ก�าหนดและสั่�งการัคอมพิ�วิเตอรั�ให#ท์�างานให#ได#

อยุ(างท์.�มน�ษยุ�ต#องการั•โปร์แกร์มคอมพิ�วเตอร์ หมายุถู+ง ชุ�ดล�าดบข้องค�าสั่�งท์.�ก�าหนดให#

คอมพิ�วิเตอรั�ท์�าการัปรัะมวิลผลข้#อม$ลเพิ��อให#แก#ป3ญหา และท์�างานได#อยุ(างท์.�ต#องการั

•Programming = Designing and writing a computer program.

Page 7: Introduction to Computer organization  & Assembly Language

ชน�ดของภาษาในการ์เข"ยนโปร์แกร์ม There are 3 kind of programming

languages• Machine language (0’s and 1’s)

• Assembly language (mov, and, or, etc…)

• High-level language (nearly like human word) Computer itself understands only Machine

language.

Page 8: Introduction to Computer organization  & Assembly Language

The translation Process

Source ProgramCompiler

/InterpreterExecutable

Program

Page 9: Introduction to Computer organization  & Assembly Language

Language translator

……main: pushl %ebp movl %esp, %ebp subl $8, %esp andl $-16, %esp movl $0, %eax subl %eax, %esp subl $8, %esp pushl $.LC0……..

Program hello;Begin writeln(“Hello world!”);End.

Interpreter/ Compiler

High-level language

Assembly language

….

00011000110001110

00110001110101111

00011111111110001

11011100001011011

……

Machine language

Hello World!

_

Assembler

Machine

Page 10: Introduction to Computer organization  & Assembly Language

Compiler

Read all program at a time. Translate into executable file (machine

language)

….writeln(‘a’);writeln(‘b’);writeln(‘c’);….

Compiler object file

library

Linker

….01001000100101 0100101.....

abc

Source

Exe file

Page 11: Introduction to Computer organization  & Assembly Language

Interpreter

Read high-level language , translate , and then execute one command at a time.

….writeln(‘a’);writeln(‘b’);writeln(‘c’);….

Inter-

preter

0100100

0100101

0100110

abc

Source

Page 12: Introduction to Computer organization  & Assembly Language

Assembler

Turns assembly symbols into machine instructions

Process this step in microprocessor

… mov A, B add B , A sub A, B push A …

Assembler

….01001000100101 0100101.....

abc

Page 13: Introduction to Computer organization  & Assembly Language

ข$อด"และข$อเสั"ยของภาษาแอสัเซมบล" ข$อด"

• สั่ามารัถูเข้.ยุนโปรัแกรัมให#ม.ข้นาดเล'กท์.�สั่�ด• โปรัแกรัมท์.�ได#สั่ามารัถูท์�างานด#วิยุควิามเรั'วิสั่$ง• สั่ามารัถูเข้.ยุนโปรัแกรัมจดการักบฮารั�ดแวิรั�ได#โดยุตรัง

ข$อเสั"ย• เข้.ยุนโปรัแกรัมได#ยุาก• แก#ไข้โปรัแกรัมล�าบาก• ไม(ม.โครังสั่รั#างข้#อม$ลรัะดบสั่$ง เชุ(น Array

• ไม(สั่ามารัถูน�าโปรัแกรัมท์.�สั่รั#างข้+8นไปใชุ#กบเครั��องต(าง CPU ได#

Page 14: Introduction to Computer organization  & Assembly Language

ข 'นตอนในการ์เข"ยนโปร์แกร์ม ว�เคร์าะห์ป)ญห์า (Analysis)

• รัะบ�ป3ญหาท์.�ต#องการัจะแก#ไข้• แบ(งป3ญหาน8นออกเป6นป3ญหายุ(อยุๆ• ค#นหาแนวิค�ดและวิ�ธ.การัท์.�จะแก#ป3ญหาน8นๆ

พิ ฒนาโปร์แกร์ม (Implementation)• เข้.ยุนโปรัแกรัมด#วิยุภาษาคอมพิ�วิเตอรั� โดยุอาศัยุแนวิค�ดการัแก#ป3ญหา

ท์.�ค�ดไวิ#ก(อนหน#า• Compile โปรัแกรัมท์.�เข้.ยุนข้+8นให#เป6นภาษาท์.�เครั��องอ(านได#

ตร์วจสัอบและแก$ไขจ.ดผิ�ดพิลาด (Testing & Debugging)• ท์ดลองรันโปรัแกรัมและตรัวิจสั่อบการัท์�างาน• หากโปรัแกรัมท์�างานไม(ถู$กต#อง หาจ�ดผ�ดให#พิบ• แก#ไข้จ�ดผ�ดพิลาดและท์ดลองใหม( จนกวิ(าโปรัแกรัมจะท์�างานได#ถู$กต#อง

Page 15: Introduction to Computer organization  & Assembly Language

พิ ฒนาการ์ของ Microprocessor Intel Zilog Motorolla 4004 8080 Z80 6800 8086,8088 Z8000 68000 80286 Z80000 6802 i386 Z80180 68030 i486 68040 Pentium

Page 16: Introduction to Computer organization  & Assembly Language

พิ ฒนาการ์ของ Intel Microprocessor

17 19 21 23 25 27 29 31 33 35 37 »Õ ¾.È. ·Õè¼ÅÔµ

ÊÁÃö¹Ð

8080

8085

8086

8088

80286

80186

80188

80386

80486

Pentium

Page 17: Introduction to Computer organization  & Assembly Language

ร์ะบบเลขจ�านวน ร์ะบบเลขฐานสั�บ

•0,1,2,3,4,5,6,7,8,9

•ไม(ม.รัหสั่ป:ดท์#ายุ เชุ(น 11001 ร์ะบบเลขฐานสัอง

•0,1

•ป:ดท์#ายุเลข้ด#วิยุ B เชุ(น 11001b หรั�อ 11001( )2

ร์ะบบเลขฐานสั�บห์ก•0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

•ป:ดท์#ายุเลข้ด#วิยุ H เชุ(น 11001h, 37DFh, 56h หรั�อ (37DF)16

Page 18: Introduction to Computer organization  & Assembly Language

การ์ค�านวณเลขฐาน

12.34 = (1 x 101) + (2 x 100) + (3 x 10-1) + (4 x 10-2)

= 10 + 2 + 0.3 + 0.04

101.012 = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2)

= 4 + 0 + 1 + 0 + 0.25

= 5.25

492.1

102 10

1 100 10

-1

Page 19: Introduction to Computer organization  & Assembly Language

จงเปล.�ยุนค(า 0625.

10

ให#เป6นเลข้ฐานสั่อง0625.

x 21.250

x 2

0.500 x

21.000

ดงน8น 025.

10

= .1012

การัแปลงเลข้ฐาน จงเปล.�ยุนค(า 1310

ให#เป6นเลข้ฐานสั่อง 2 13

6เศัษ 1 3เศัษ 0 1เศัษ 1 0เศัษ 1ดงน8น 1310 = 11012

Page 20: Introduction to Computer organization  & Assembly Language

การัจดการัเลข้ฐานสั่อง

การัลบเลข้ 100111. กบ

1011. 1001 .

11 - 101 10.

100 . 01

การับวิกเลข้ 1011101.2

กบ 110011.2

1011 101. + 110 011. 1 0010 000.

การัค$ณ์เลข้ฐานสั่อง 1. 01 x 10.1

1 . 0 1 x 1 0 . 1 0

1 0 10 0 0

1 0 1 1 1 . 0 0 1

Page 21: Introduction to Computer organization  & Assembly Language

ตาร์างเปร์"ยบเทำ"ยบค2าของเลขฐาน 2,8,16

เลขฐานสั�บ เลขฐานสัอง เลขฐานแปด เลขฐานสั�บห์ก 0 0000 0 0 1 0001 1 1 2 0010 2 2 3 0011 3 3 4 0100 4 4 5 0101 5 5 6 0110 6 6 7 0111 7 7 8 1000 10 8 9 1001 11 9 10 1010 12 A 11 1011 13 B 12 1100 14 C 13 1101 15 D 14 1110 16 E 15 1111 17 F

Page 22: Introduction to Computer organization  & Assembly Language

2 ’s complementเลข้ฐาน 10

เลข้ฐาน 2 (1’s complement)

ฐาน 1

0

เลข้ฐาน 2 1( ’s complement)

0 00000000 0

1 00000001 -1

2 00000010 -2

3 00000011 -3

4 0000 0100 -4เลข้ฐาน 10

เลข้ฐาน 2 2( ’s complement)

ฐาน 1

0

เลข้ฐาน 2 (2’s complement)

0 00000000

1 00000001 -1 1111 1111

2 00000010 -2 1111 1110

3 00000011 -3 1111 1101

4 0000 0100 -4 1111 1100

1111 1111

1111 1110

1111 1101

1111 1100

1111 1011

Page 23: Introduction to Computer organization  & Assembly Language

ข$อก�าห์นดของ 2’s complement ต#องก�าหนดจ�านวินบ�ตสั่$งสั่�ดท์.�ใชุ#งาน เชุ(น 4 บ�ต 8, บ�ต

(บ�ตท์.�ล#นออกมาในการัค�านวิณ์จะหายุไป) ใชุ#บ�ตนยุสั่�าคญสั่$งสั่�ดเป6นตวิบอกเครั��องหมายุ เลข้ท์.�ตรังกนข้#ามจะต#องบวิกกนได#ศั$นยุ� การัเปล.�ยุนเลข้ให#ม.เครั��องหมายุตรังข้#าม สั่ามารัถูท์�าได#โดยุ

การักลบตวิเลข้ท์8งหมดท์�กบ�ตจาก 0->1 และจาก 1->0 จากน8นบวิกด#วิยุค(า 1

จ�านวินตวิเลข้ท์8งหมดท์.�ใชุ#ได#ค�อ 2bit ตวิ •สั่�าหรับเลข้ 8 บ�ตจะม.ท์8งหมด 28 = 256 ตวิ และม.ค(า

- 128 ถู+ง 127+

Page 24: Introduction to Computer organization  & Assembly Language

Question ?