Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
19-Jun-06 Assembly Language ([email protected]) 1
ระบบคอมพิวเตอรเบื้องตนระบบคอมพิวเตอรเบื้องตน
ปรีดาปรีดา เลิศพงศวิภูษณะเลิศพงศวิภูษณะplw@[email protected]
ภาควิชาวิศวกรรมคอมพิวเตอรภาควิชาวิศวกรรมคอมพิวเตอรคณะวิศวกรรมศาสตรคณะวิศวกรรมศาสตร มหาวิทยาลัยเกษตรศาสตรมหาวิทยาลัยเกษตรศาสตร
19-Jun-06 Assembly Language ([email protected]) 2
ระบบระบบ Hardware Hardware ของคอมพิวเตอรของคอมพิวเตอร
รีจีสเตอรRegister
ALUArithmetic Logic Unit
หนวยควบคุมControl Unit
หนวยประมวลผลกลางCentral Processing Unit
หนวยแสดงผลOutput Unit
หนวยนําขอมลูเขาInput Unit
หนวยความจําMemory Unit
19-Jun-06 Assembly Language ([email protected]) 3
The Big PictureThe Big PictureSince 1946 all computers have had 5 components
Control
Datapath
Memory
ProcessorInput
Output
19-Jun-06 Assembly Language ([email protected]) 4
ระบบระบบ Hardware Hardware ของคอมพิวเตอรของคอมพิวเตอร
19-Jun-06 Assembly Language ([email protected]) 5
CPU Pentium 4CPU Pentium 4
19-Jun-06 Assembly Language ([email protected]) 6
Dual Core and Dual Core and HyperThreadHyperThread
19-Jun-06 Assembly Language ([email protected]) 7
19-Jun-06 Assembly Language ([email protected]) 8
19-Jun-06 Assembly Language ([email protected]) 9
19-Jun-06 Assembly Language ([email protected]) 10
19-Jun-06 Assembly Language ([email protected]) 11
Memory HierarchyMemory Hierarchy
DISK
MEMORY
CACHE
REGISTERSFaster
Slower Larger
Smaller
19-Jun-06 Assembly Language ([email protected]) 12
Processor PerformanceProcessor Performance TrendsTrends
Microprocessors
Minicomputers
Mainframes
Supercomputers
Year
0.1
1
10
100
1000
1965 1970 1975 1980 1985 1990 1995 2000
19-Jun-06 Assembly Language ([email protected]) 13
ชนิดของชนิดของ SoftwareSoftwareSystem SoftwareSystem Application Program Interface (API)Application Software
19-Jun-06 Assembly Language ([email protected]) 14
ความสัมพันธของความสัมพันธของ Hardware Hardware และและ SoftwareSoftware
ระบบปฏิบัติการOperating System
คอมพิวเตอรComputer Hardware
ซอฟตแวรประยุกตApplication
ระบบเชื่อมตอSystem Application Program Interface
ซอฟตแวรประยุกตApplication
Basic Input Output System(BIOS)
Device Driver
User
19-Jun-06 Assembly Language ([email protected]) 15
What are What are ““Machine StructuresMachine Structures””??
I/O systemProcessor
CompilerOperating
System(Windows 98)
Application (Netscape)
Digital DesignCircuit Design
Instruction SetArchitecture
Datapath & Control
transistors
MemoryHardware
Software Assembler
19-Jun-06 Assembly Language ([email protected]) 16
Levels of RepresentationLevels of RepresentationHigh Level Language
Program
Assembly Language Program
Machine Language Program
Control Signal Specification
Compiler
Assembler
Machine Interpretation
temp = v[k];v[k] = v[k+1];v[k+1] = temp;
lw $15, 0($2)lw $16, 4($2)sw $16, 0($2)sw $15, 4($2)0000 1001 1100 0110 1010 1111 0101 1000
1010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111
°°
ALUOP[0:3] <= InstReg[9:11] & MASK
19-Jun-06 Assembly Language ([email protected]) 17
Execution CycleExecution CycleInstruction
Fetch
InstructionDecode
OperandFetch
Execute
ResultStore
NextInstruction
Obtain instruction from program storage
Determine required actions and instruction size
Locate and obtain operand data
Compute result value or status
Deposit results in storage for later use
Determine successor instruction
19-Jun-06 Assembly Language ([email protected]) 18
From Sand to SupercomputersFrom Sand to Supercomputers
PC System:PCBs, Hardware,
& Software
PrintedCircuit Board:
≈8-16 ICs + wires
Cell:≈2-16 gatesLogic Gate:
≈2-8 MOSFETs
MOSFETtransistor
≈ < 1μ2 of Si and Metal
Integrated Circuit:≈8-16 Modules
in a “Chip”
Sand (SiO2)
Electrons
Module:≈1K-10K Cells
The Net≈ 50M PCs
working together
19-Jun-06 Assembly Language ([email protected]) 19
19-Jun-06 Assembly Language ([email protected]) 20
19-Jun-06 Assembly Language ([email protected]) 21
19-Jun-06 Assembly Language ([email protected]) 22
19-Jun-06 Assembly Language ([email protected]) 23
19-Jun-06 Assembly Language ([email protected]) 24
19-Jun-06 Assembly Language ([email protected]) 25
ระบบเลขจํานวนระบบเลขจํานวน
ปรีดาปรีดา เลิศพงศวิภูษณะเลิศพงศวิภูษณะplw@[email protected]
ภาควิชาวิศวกรรมคอมพิวเตอรภาควิชาวิศวกรรมคอมพิวเตอรคณะวิศวกรรมศาสตรคณะวิศวกรรมศาสตร มหาวิทยาลัยเกษตรศาสตรมหาวิทยาลัยเกษตรศาสตร
19-Jun-06 Assembly Language ([email protected]) 26
ความหมายของตัวเลขในหลักตางความหมายของตัวเลขในหลักตาง ๆๆเลขฐานสิบ
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
19-Jun-06 Assembly Language ([email protected]) 27
การแปลงเลขฐานสิบเปนฐานสองการแปลงเลขฐานสิบเปนฐานสองเปลี่ยนคา 1310 ใหเปนเลขฐานสอง
132
6 เศษ 12
3 เศษ 02
1 เศษ 12
0 เศษ 1
1310 = 11012
19-Jun-06 Assembly Language ([email protected]) 28
การแปลงเลขฐานสิบเปนฐานสองการแปลงเลขฐานสิบเปนฐานสองเปลี่ยนคา 0.2510 ใหเปนเลขฐานสอง
0.25
2
0.50
X
2
1.00
X
0.012
0.2510 = 0.012
19-Jun-06 Assembly Language ([email protected]) 29
การบวกและลบเลขฐานสองการบวกและลบเลขฐานสองการบวกn บวกเลข 1011.1012 กับ 110.0112
19-Jun-06 Assembly Language ([email protected]) 30
การบวกและลบเลขฐานสองการบวกและลบเลขฐานสองการลบn ลบเลข 1001.11 กับ 101.1
19-Jun-06 Assembly Language ([email protected]) 31
การคูณและหารเลขฐานสองการคูณและหารเลขฐานสองการคูณn คูณเลขฐานสอง 1.01 x 10.1
19-Jun-06 Assembly Language ([email protected]) 32
การคูณและหารเลขฐานสองการคูณและหารเลขฐานสองการหารn หารเลขฐานสอง 11001 ÷ 101
01 0 1
00 0
1 0 1
1
0
1 0 1
1 0 1
1 0
101
101
19-Jun-06 Assembly Language ([email protected]) 33
เลขฐานแปดและเลขฐานสิบหกเลขฐานแปดและเลขฐานสิบหกเลขฐานสิบ เลขฐานสอง เลขฐานแปด เลขฐานสิบหก
0 0000 0 01 0001 1 12 0010 2 23 0011 3 34 0100 4 45 0101 5 56 0110 6 67 0111 7 78 1000 10 89 1001 11 9
10 1010 12 A11 1011 13 B12 1100 14 C13 1101 15 D14 1110 16 E15 1111 17 F
19-Jun-06 Assembly Language ([email protected]) 34
เลขฐานสองและเลขฐานสิบหกเลขฐานสองและเลขฐานสิบหกจัดกลุมเลขฐานสองเปนชุดๆ ชุด 4 บิต โดยนบัจากบิตขวาสดุที่เปนเลขที่มีนัยสาํคัญต่ําที่สุดถาจําเปนใหเติมศนูยดานหนาเพื่อใหครบ 4 บิตแปลงเลขแตละชดุใหเปนเลขฐานสิบหกโดยเริม่จาก 0 - 9 และ A - F
19-Jun-06 Assembly Language ([email protected]) 35
บิตบิต,, ไบตไบต,, นิบเบิลนิบเบิล,, เวิรดเวิรด
19-Jun-06 Assembly Language ([email protected]) 36
Character DataCharacter DataAmerican Standard Code for Information Interchange (ASCII)n a 7-bit binary code for a set of 128 charactersn usually occupy a byte of storagew leading bit may be ignored or used differently by various programs
n a sequence of bytes containing ASCII codes is referred to as an ASCII string
19-Jun-06 Assembly Language ([email protected]) 37
การแทนคาเลขลบในระบบฐานสองการแทนคาเลขลบในระบบฐานสอง2’ Complement
0011 = 3, 1101 = -30101 = 5, 1011 = -5
Sign and Magnitude
0011 = 3, 1011 = -30101 = 5, 1101 = -5
* หมายเหตุ: เลขท้ังหมดเปนเลขขนาด 4 บิต *
19-Jun-06 Assembly Language ([email protected]) 38
ขอกําหนดของขอกําหนดของ 22’’ComplementComplementตองกําหนดจํานวนบิตสูงสุดที่ใชงาน (บิตที่ลนออกมาในการคํานวณ จะ
หายไป)ใชบตินัยสําคัญสงูสุดเปนตัวบอกเครื่องหมายเลขที่ตรงกนัขามจะตองบวกกันไดศูนย
19-Jun-06 Assembly Language ([email protected]) 39
TwoTwo’’s Complement Sign Changes Complement Sign ChangeThe 2’s Complement codes for x and -x add to a power of 2n 8-bit code: c+(-c)=28
n 16-bit code: c+(-c)=216
(-c)=2n-c=[(2n-1)-c]+1n Note that (2n-1) is 1111..1b, making
subtraction a cinch!n Roles of (-c) and c can be reversed
Change Sign Rule In Subtract from 2n
Change Sign Rule IIn Flip all the bitsn Add 1
Change Sign Rule IIIn Scan right to left to the first bit with
value 1n Flip all bits to its left
19-Jun-06 Assembly Language ([email protected]) 40
เลขเลข BCDBCD
0 0 1 1 0 1 1 01 หลัก 1 หลัก
= 36
00110110 + 00011001 = 0101010100110110 - 00011001 = 00010111
19-Jun-06 Assembly Language ([email protected]) 41
IEEE754IEEE754SEEEEEEEEMMMMMMMMMMMMMMMMMMMMMMM
(-1 * S)1.M * 2E-B
B = 127 (กรณีของ 32 bit)0 10000000 0100000000000000000000= (-1*0)1.01 * 2 128 - 127
= 2.5
19-Jun-06 Assembly Language ([email protected]) 42
Storage Sizes and RangesStorage Sizes and RangesUnsigned Integer
Byten 0 to 255
Wordn 0 to 65,535
Doublewordn 0 to 4,294,967,295
Quadwordn 0 to 18,446,744,073,709,551,615
Signed (2’s Complement Code)Byten -128 to 127
Wordn -32,768 to 32,767
Doublewordn -2,147,483,648 to 2,147,483,647
Quadwordn -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807
19-Jun-06 Assembly Language ([email protected]) 43
ภาษาสําหรับเขียนโปรแกรมภาษาสําหรับเขียนโปรแกรม
ปรีดาปรีดา เลิศพงศวิภูษณะเลิศพงศวิภูษณะplw@[email protected]
ภาควิชาวิศวกรรมคอมพิวเตอรภาควิชาวิศวกรรมคอมพิวเตอรคณะวิศวกรรมศาสตรคณะวิศวกรรมศาสตร มหาวิทยาลัยเกษตรศาสตรมหาวิทยาลัยเกษตรศาสตร
19-Jun-06 Assembly Language ([email protected]) 44
ภาษาสําหรับเขียนโปรแกรมภาษาสําหรับเขียนโปรแกรมภาษาระดับต่ําn ภาษาเครื่อง, ภาษาแอสเซมบลี
ภาษาระดับสูงn ภาษา C, C++, C#, Javan ภาษา Basic, Visual Basicn ภาษาฟอรแทรน, COBOL
19-Jun-06 Assembly Language ([email protected]) 45
การแปลภาษาคอมพิวเตอรการแปลภาษาคอมพิวเตอรใชแปลภาษาจากระดับสูงไปสูระดับต่ําn Compilern Interpretern Just In Time Complierใชแปลภาษาแอสเซมบลไีปเปนภาษาเครื่องn แอสเซมเบลอร
19-Jun-06 Assembly Language ([email protected]) 46
ขอดีและขอเสียของภาษาแอสเซมบลีขอดีและขอเสียของภาษาแอสเซมบลีขอดีn สามารถเขียนโปรแกรมใหมีขนาดเล็กที่สุดn โปรแกรมที่ไดสามารถทํางานดวยความเร็วสูงn สามารถเขียนโปรแกรมจัดการกับฮารดแวรไดโดยตรงขอเสียn เขียนโปรแกรมไดยากn แกไขโปรแกรมลําบากn ไมมีโครงสรางขอมูลระดับสูง เชน Array, Objectn ไมสามารถนําโปรแกรมที่สรางขึ้นไปใชกับเครื่องตาง CPU ได