This presentation is the property of its rightful owner.
Sponsored Links
1 / 72

زبان ماشین و اسمبلی PowerPoint PPT Presentation


  • 212 Views
  • Uploaded on
  • Presentation posted in: General

زبان ماشین و اسمبلی. جزوه درس زبان ماشین واسمبلی دانشگاه روزبه زنجان استاد فروتن راد مينا مغربي. بسم تعالی. دلايل مطالعه ي درس اسمبلي :. ج 1. آشنايي با معماري سخت افزاري برنامه نويسي روي سخت افزار كنترل سخت افزار هاي ويژه ( روبات ) امكان تركيب با نرم افزار يا زبان هاي ديگر. C , HTML…

Download Presentation

زبان ماشین و اسمبلی

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


4849312


4849312


4849312

:

1

  • ( )

C , HTML

ASM

MOV . Ax . 10

end ASM


4849312

:

  • 80x86 :

    Intel

    80 86 , 80 88 , 80x86 , 80 286 ,80 386

Main memory

C p u

Registerbank

c . u

A . L . U

I / O

SYSTEM BUS


80x86

80x86 :

  • :

    CPUcentral processing unit

    .

  • :

    control unit CU

    .

    : .

    : .


4849312

  • :

    A . L . UArithmetic and Logic Unit

    .

    1. arithmetic unit ... .

    2. logic unit not ,mod, or , x or , and .

  • :

    Registers

    flash memory .

ram

n

5v

3.5

0 3.5 = 0

3.5 - 5 = 1

t


4849312

5v

Flash memory

.

  • main memory :

BF 9D

64

BF 9F

0040h

data


4849312

  • :

    Random access memory Ram

    ram .

  • SRAM = Static RAM

  • DRAM = Dynamic RAM

    Single DRAM (SDR)

*

SDR

Double DRAM (DDR)

*

CLOCK PLUS

DDR

CLOCK PLUS

*


4849312

  • :

    Read Only Memory ROM

    BIOS ROM ROM .

    BIOS = *

Programmable ROM = PROM

Electronic PROM = EPROM

* main memory Ram .


I o device

/ I/O Device :

.

  • : .

    * .

    Data :

    : Information

FSB

( , ram , )Main

400

GHz

1068


4849312

10 2 :

2

2 .

10 2 0 2 , 2 10 .

194

2

2

18 97

:

(194)10=(11000010)2

2

14 8 48

2

14 17 4 24

2

0 16 8 2 12

2

1 8 4 12 6

2

0 4 0 6 3

0 0 2 1

1


4849312

10 2 , .

: (194)10=(11000010)2

194

27

128

=

2

66

26

=

64

2

21

=

2

20

=

0


4849312

2 10 :

2 10 .

2 10 , , , ... , , , ... .

: (11000010)2 = (194)10

  • 27

25

23

21

  • 1 * 2^7 + 1 * 2^6 + 0 * 2^5 + 0 * 2^4 + 0 * 2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0 = 194

(11000010)

  • 26

24

22

20


4849312

:

.

:

) 0 + .

) 1 .

Sign bit

+

=

67

-

* 2 + .


4849312

(01000011) 2= (+67) 10

1 :

.

(10111100) 2 = (-67 ) 10

* 2 , , ... .

2 :

3 .

1: 2 .

(01000011) 2 =(+67) 10

(10111100)

+

1

(10111101) 2 =(-67) 10


4849312

2

(011010000)

( 10011000)

2 : 1 0 0 .

3 : .

1

1

1

1

1

1

1

0

10

10

10

10

10

10

10

10

1 0 0 0 0 0 0 0 0

- 0 1 0 0 0 0 1 1

(101111101) = (-67)

  • :

  • 1 2 8 (8 , 16 , 32 ... ) .

  • 2 , 1 0 .

  • 1 1 .


4849312

2 :

( ) .

:

,Dn D2,D1,D0 .

- Dn * 2^n + dn-1 * 2^n-1 + + d1 * 2^1 + d0 * 2^0

(10111101) = (-67)

- 1 * 2^7 + 0 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 =

-128 + 32 + 16 + 8 + 4 + 1 = - 67


4849312

8 16

:

m

2^m+1 1 (- DN * 2^n + dn-1 * 2^n-1 + + d1 * 2^1 + d0 * 2^0)

2^i

=

i=0

: 8

0 0 0 0 0 0 0 1

=

128-

1 1 1 1 1 1 1 0

=

127+

: 16

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

=

32768 -

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0

32767 +

=


8 16 octal hexadecimal

8 16 (Octal , Hexadecimal):

2 8 16 .

:


4849312

8 16 .

2 8 :

8 2 8 .

8(233530)=2(010011011101011000)

8 2 :

8 2 8 , 3 2 .

2(010011011101011000)=8(233530)


4849312

2 16 :

2 16 4 4 .

H(13758)=(000100110111101011000)2

(1110101111110101)2=(EBF5)H

  • :

  • 16 16 0 .

  • 8 0 3

  • + 4 7 16 0 7 + 8 f .

(0EBF5)h

16

8(7013)

8(3777)

16(FB47)

16(EB43)

-

+

-

+


4849312

:

. ,

:ASCII(American Standard Code for Information Interchange )

ASCI ( ) ) ).


4849312

  • ( 7 ) Unicode 16 (2) (SUPER COMPUTER) EBCDIC (EXTENDED BINARY CODE DECIMAL INFORMATION CODE) .

warning

.


4849312

:

c o m p u t e r s

43

6f

6e

71

75

74

65

72

73

Enter(0d)

ram

a r e

73

0b74

Enter(0d)

61

72

65

70

65

74

Enter(0d)

f u n

66

75

6e


4849312

:

10 2 :

(01000011.01011111)

67/373

=

....

373 .

2

=

0.746

*

1.492

746 .

2

=

*

0.984

492 .

2

=

*

1.968

984 .

2

=

*

2

1.936

968 .

=

*

1.862

936 .

2

=

*

1.724

862 .

*

2

=

2

=

1.448

724 .

*


4849312

2 10 :

128

1

...

(67.373)= (01000011.01011111)

...

56

0.373

1/256* 1 + ...1/16 * 1+ 1/8 * 0 + * 1 + * 0

:

delete backspace .


4849312

2 :

3

X

111

(0A07) H

+

(01D3) H

(0BDA) H

0000101000000111

+

0000000111010011

0000101111011010

1

X

(0206) H

+

(FFB0) H

(101B6) H

111111

0000001000000110

+

1111111110110000

10000001110110110

2

( )Carryout


4849312

X

1

11111

(E9FF) H

+

(8CF0) H

(176EF) H

1110100111111111

+

1000110011110000

10111011011101111

3

1111111111

11

(FFE7) H

+

(FFF6) H

(1FFDD) H

1111111111100111

+

1111111111110110

11111111111011101

4


4849312

1

(493F) H

+

(645A) H

(AC99) H

01001000001111111

+

011001100001011010

1010110010011001

5

X

: Over flow

.

1. + , - .

2. - , + .

3. .

.


4849312

.


4849312

  • register:

    flash memory (buffer) .

  • (buffer) :

    .

  • 80x86 :

    4 80x86 EDX,ECX,EBX,EAX .


4849312

:

8

8

EAX :

Ah

Al

16

AX=16

32bit

8

8

EBX :

Bh

Bl

16

BX=16

32bit

8

8

ECX :

Ch

Cl

16

CX=16

32bit


4849312

8

8

EDX :

Dh

Dl

16

DX=16

32bit

  • :

  • 32 .

  • 80x86 80x286 16 80x386 32 .

  • EAX Accumulator :

Mulbl ; ax bl * al

bl al ax .


4849312

: segment

ram ( ) (data segment ) (stack segment ) (extra segment ) .

Main memory

80x86 , 4 (ES , SS , DS , CS ) .

Code segment

CS

Data segment

DS

program

Stack segment

SS

Extra segment

ES


4849312

(stack) :

(LIFO first in first out) item .

(sp stack pointer) , 4 .


4849312

, sp .

push

pop

item

0011

SP

0011

2

d

1

d

SP

1

0010

c

SP

0010

c

SP

2

0001

b

0001

b

0000

a

0000

a

SS

SS

Push :

Sp .

sp .

Pop :

Sp .

sp .


4849312

, sp .

push

pop

item

SP

2

SP

0011

0011

1

d

d

SP

2

SP

1

0010

c

0010

c

0001

b

0001

b

0000

a

SS

0000

a

SS

  • Push :

  • sp .

  • Sp .

Pop :

sp .

Sp .


4849312

, sp .

SS

SS

FFFF

a

FFFF

a

FFFE

b

FFFE

b

FFFD

c

FFFD

c

SP

2

SP

FFFC

d

1

d

2

FFFC

SP

1

SP

item

push

pop

Push :

Sp .

sp .

  • Pop :

  • Sp .

  • sp .


4849312

, sp .

SS

SS

FFFF

a

FFFF

a

FFFE

b

FFFE

b

FFFD

c

FFFD

c

SP

1

FFFC

d

SP

d

1

FFFC

2

SP

2

SP

item

push

pop

  • Push :

  • sp .

  • Sp .

  • Pop :

  • sp .

  • Sp .


4849312

:

4

... .

[ Label ] Instruction . Name [ operand ] [; comments]

For example :

LBL : MOV EAX ,EDX ; copies data in EDX to EAX

Add CX ,BX

CWD

:

(0) :

.no LST

.LST .

80x286 , 80x386 486. 586. .

386.

.model flat

32 .


4849312

:

( ) .

F1(){

.

.

.

F2 () ;

.

.

.

}

F2(){

.

.

.

.

}

m1(){

.

.

.

invok m2 ()

.

.

}

m2(){

.

.

.

.

}

m2 invok m2 .


4849312

:

T byte , Q word , D word , word , byte , , , real 10 , real 8 , real 4 4 , 8 10 .

Operand-name memory-amount initialize-value

Data segment

Example :

1byte

CH

41h

Number D word 10

Ch byte A

offset .

10

number

4byte

offset

D S

Main Memory


4849312

:

.

STR byte computer are fun , 0

STR

43h

6fh

.

6dh

1

1

10

Main memory


4849312

:

.

Array word 10,50,63,74

array

Char byte a , l , I

10

Array[0]

50

Array[1]

63

Array[2]

74

Array[3]

.

DS


4849312

dup:

numbers 10 1 ( ) .

Number byte 10 dup( ? )

Null

B 10 = 1 * 10 =

* =

) .

Stars byte 24 Dup (* ) , *

*...* * *

25

) 10 .

) *****#### STR byte 10 dup (

***** ####

dup .

STR byte 10 (5 dup() , 4 dup (#) , 5 dup (*)


4849312

:

80x86 2 EBP, ESP 32 16 sp 80x386 ( 80x86 .) 80x86 3 .

EBP .

SS

FFFF

a

FFFE

b

BP

FFFD

c

d

FFFC

e

FFFB

SP

stack


4849312

:

80x86 2 EDI , ESI , ESI EDI . EIP(Instruction Pointer) .

e flag :

, , ... .

31

12

11

10

9

8

7

6

5

4

3

2

1

0

DF

SF

ZF

PF

CF

OF

....

16

CF = Carry flag ZF = Zero flag SF = Sign flag DF = Direct flag PF = Parity flag OF = Over flow flag

flag , ES , SS , DS , CS EIP , SP .

MOV EIP , 158 ; error


4849312

* flat ES , SS , DS , CS .

* OFFSET CS (CODE SEGMENT) .

Main memory

Codesegment

CS

Data segment

DS

program

Stack segment

SS

Extra segment

ES


4849312

:

5

.

1. :

1. Example : MOV AX , 179

ADD CX , -74

.

2. :

2. Example : MOV EAX , ECX

ADD BX , 23

, Offset segment DS .

3. :

3. Example : SUM WORD ?

NUMBER DWORD 20

.

.

.

MOX

Codesegment

Datasegment

data

variable

offset

Ds

Stacksegment

Extrasegment


4849312

(EDX,ECX,EBX,EAX) EDI , ESI . EBP ESP PTR .

4. :

4. Example : MOV EAX , [EDX]

.

.

.

EDX

  • , ( ) .

  • .

Main memory

DATA

EAX .

5. :

5. Example : MUL BL ; AX BL * AL


4849312

IO.H:

IO.H 32 , 6 .

1

A to d source

source EAX .

1

SOURCE

Main memory

NULL

7

5

8

9

\0

A to D

EAX : 75894Byte


4849312

2

D to A Destination source

4 SOURCE 11 DESTINATION .

2

Destination SOURCE

Main memory

NULL

-

4

9

7

3

\0

D to A

EAX : -49734Byte

3

A to W source

SOURCE 2 AX .

3

SOURCE

Main memory

NULL

-

7

2

\0

A to W

AX : -722Byte


4849312

W to A Destination source

4

4

2 SOURCE 6 DESTINATION .

DESTINATON SOURCE

Main memory

NULL

5

0

\0

W to A

AX : 502Byte

Input Destination, length

5

length destination .

5

output source, [length]

6

source null .

6

Length =

destination=

source=


4849312

:

6

:

: move

80x86 move , , source destination .

MOV Destination , source ; destination source

Example : MOV EAX , EDX ; Copies data in EDX in to EAX

Example : MOV NUMBER , EAX ; Copies data in ECX in to a variable whose name is number

: Ex change

80x86 ex change , , destination1 destination 2 .

XCHG Destination1 , destination2 ; destination1 destination 2

Example : XCHG EAX , EDX ; swap value of EAX and value of EDX


4849312

  • MOV .

MOV .

1. MOV number 1 , number 2 ; error

2. .

2. MOV CS , OF 9BH ; error

3. .

3.MOV CS , DS; error

4. .

4.MOV EIP , 1B 4CH; error

5. .

5.MOV EAX , EFLAG; error

6. .

6. MOV EBX , CL; error

  • MOV XCHG .


4849312

:

ADD : 80X86 ADD 2 , destination source destination :

ADD Destination , source ; destination destination + source

sub : 80X86 sub 2 , source destination destination :

sub Destination , source ; destination destination - source

inc : .

inc Destination; destination destination + 1


4849312

DEC: .

DEC Destination; destination destination - 1

NEG: 2 .

NEG Destination; destination - destination


4849312

7

:

80x86 mull , I mull 2 mull I mull mull I mull .

mull : .

Mull source ;

1. source ( ) mull () source source AL AX . source AX DX:AX DX AX source EAX EDX : EAX . EDX EAX .


4849312

1 BYTE

AL

2 BYTE

SOURCE

2 BYTE

AX

1

*

2 BYTE

AX

2 BYTE

SOURCE

2 BYTE

DX

2 BYTE

AX

2

*

4 BYTE

EAX

4 BYTE

SOURCE

4 BYTE

EDX

4 BYTE

EAX

3

*

1 ) ( AL * SOURCE AX )

2) ( AX * SOURCE DX : AX )

3) ( EAX * SOURCE EDX : EAX)

1) Example :

MOV AX,10

MOV BX,5

MULL BX,DXAX BX * AX (DXAX) B * 10 AX = 50 DX = 0

MULL 2 ; Error


4849312

I mull : 3 .

1) I Mull source

I mull mull mull I mull mull source I mull .

2) I Mull register source ; register register * source

2. I mull source ( ) (register) 2 4 1=CF=OF .

2) Example :

MOV AX,50

I MULL AX , 2 ;AX 100

I MULL AL , 2 ; Error

I MULL AL , CH ; Error

I MULL AX , BL ; Error


4849312

3) I Mull register , source immediate ; register source * immediate

2. I mull register 1 . source ( ) . immediate 1=CF=OF .

3) Example :

Data

number D Word 50

code

I MULL EBX,NUMBER,10;EBX 50*10


4849312

8

:

80x86 Div , I Div div I div div I div .

+

Div source

+ -

I Div source

source ( ) . () source source ax al ah . 4 DX : AX AX DX source 4 8 EDX : EAX EAX EDX .


4849312

AX

AL=1B

AH=1B

2 BYTE

AX

1 BYTE

SOURCE

AX

1

2 BYTE

DX

2 BYTE

AX

2 BYTE

SOURCE

2 BYTE

DX

2 BYTE

AX

2

4 BYTE

EDX

4 BYTE

EAX

4 BYTE

SOURCE

4 BYTE

EDX

4 BYTE

EAX

3

Example :

. Data

number D Word 10

. Code

AH DIV CL; AX CL AL

DX DIV BX; DXAX BX AX

EDX I DIV NUMBER; EDX:EAX NUMBER EAX

DIV 5; ERROR


4849312

CBW (CONVERT BYTE TO WORD) CWD (CONVERT WORD TO DOUBLE ) (CONVERT DOUBLE TO QUAD WORD)CDQ . CBW AL AX CDQ EAX EDX : EAX .

  • .

CBW

1

1

1

1

1

1

1

1

1

0

0

0

0

0

0

+127

AL

AH

AX

0

0

0

0

0

0

0

0

0

1

1

1

1

1

1

-127

AL

AH

AX


4849312

CBW,CWD,CDQ .

MOV ZX REGISTER , SOURCE

MOV SX REGISTER , SOURCE

SOURCE REGISTER SOURCE REGISTER 2 SOURCE 2 REGISTER 4 .

MOV ZX REGISTER SOURCE MOV SX REGISTER SOURCE SOURCE .

EXAMPLE :

MOV BX,10

MOV ZX EAX,BX

BX

000A h

EAX

0000 000Ah

EXAMPLE :

MOV BL,-128

MOV SX BX,BL

BL

80 h

BX

FF h 80h


4849312

:

80x86 SBB ,ADC .

ADC destination , source ; destination destination + source + CF

SBB destination , source ; destination destination - source - CF


4849312

:

9

IF CASESWITCH FOR,WHILE,DOWHILE EIP EIP .

:

80x86 JUMP GO TO statement address EIP JMP .

statement - address

Example :

LBL1 : MOV AX ,244

JMP LBL2

LBL2 : ADD ECX, EDX

JMP LBL1

LBL1 .


4849312

:

80x86 FLAG statement address .

J--- statement - address

:

A=ABOVE=

B=BELOW=

E=EQUAL=

N=NOT=

G=GREAT=

L=LITTLE=


4849312

CMP

  • CMP OPERAND 2 OPERAND 1 .

CMP OPERAND1.OERAND2

Example :

CMP EDX . EAX

CMP CL , BH

CMP AX , 1024

1024 AX

+ AX 1024 .

- AX 1024 .


4849312


  • Login