Assembly [Ελληνικο Μαθημα]

download Assembly [Ελληνικο Μαθημα]

of 130

  • date post

    14-Oct-2015
  • Category

    Documents

  • view

    16
  • download

    0

Embed Size (px)

description

Assembly [Ελληνικο Μαθημα]

Transcript of Assembly [Ελληνικο Μαθημα]

  • 5/24/2018 Assembly [ ]

    1/130

    1

    1

    8086

    8086 Intel, (1978) 16-bit. , .

    1.8086

    8086 , 1, :

    1

    - (EU, Execution Unit), . , , ,

    .

    - (BIU, Bus Interface Unit) / ( ). /. , (Instruction Pointer, IP), , bytes .

    "pipeline", , EU

  • 5/24/2018 Assembly [ ]

    2/130

    2

    BIU (queue) BIU. (.. ) BIU / . EU .

    (bus), /16 bits, 20

    bits.

    2.

    2.1 (Data Registers).

    :AX ( = accumulator),

    BX ( = base),

    CX ( = counter),

    DX ( = data ).

    16-bit 8-bit . H (High) L (Low). 8-bit : AH,AL, BH, BL, CH, CL, DH, DL. , .. , :

    / , , , .

    BX (indirectaddressing).

    CX .

    DX AX 16 bits 32 bits ,.

    2.2 .

    16 bits, (pointer, index) , , , . :

    SP ( = Stack Pointer),

    BP ( = Base Pointer),

    SI ( = Source Index),

    DI (= Destination Index),

    :

  • 5/24/2018 Assembly [ ]

    3/130

    3

    SP .

    BP ( ,).

    SI .

    DI .

    2.3

    IP ( = Instruction Pointer) (offset) . BIU. (Program Counter)von Neumann :

    CS : IP

    2.4 .

    2.

    SR16bits, 9 .

    2.4.1 .(6 bits)

    ( ON , OFF ) , , . () . :

    CF (Carry Flag)

  • 5/24/2018 Assembly [ ]

    4/130

    4

    (ADD,SUB, ADC, SBC). () () Msbit , 1 0. (RCR, RCL). Msbit

    bit 71byte 151word = 2bytes.

    AF (Auxiliary Flag)

    34bit byte, 1 0. BCD (DAA,AAA).

    SF (Sign Flag)

    . Msbit (7 15) . 0 , 1.

    ZF (Zero Flag)

    1 0, 0.

    OF (Overflow Flag)

    1 () . (eXclusive-OR) Msbit .

    PF (Parity Flag)

    . 1 1 byte .

    .

    2.4.2 .(3 bits)

    ( ,, ).

    IF (Interrupt Flag)

  • 5/24/2018 Assembly [ ]

    5/130

    5

    1 IF, , . ().

    DF (Direction Flag)

    . 1 (SI DI) /, .

    TF (Trap Flag)

    1 . .

    2 . .. T Trap Flag.

    2.5 .

    (segments) :

    - CS(= Code Segment).- DS(= Data Segment).- SS(= Stack Segment).- ES(extra = Extra Segment).

    3. .

    /8086 DIL (Dual InLine) 40 (pins) . (Minimum) (Maximum). 5V 0V /. Minimum / , Maximum 8288. 8087 8089.

    8086 (Multiplex) . 20 , (Address

  • 5/24/2018 Assembly [ ]

    6/130

    6

    Data) (AD0 AD15) (System Address) (A16 S3 A19 S6). , , ( ALE Address Latch Enable )

    . BIU.

    3

    :

    - GND.- NMI.- INTR.- CLK

    CPU.

    - RESET. , 0FFFF0h (IP=0000,CS=0FFFFh). / ROM JMP

  • 5/24/2018 Assembly [ ]

    7/130

    7

    / . bootstrap loader.

    - READY /,

    .

    - TEST WAIT .

    - RD .

    - VCC +5V 10%.- S3, S4

    /.

    - S5(IF).- S6

    .

    - QS0(ALE), QS1 (INTA). .

    - S0, S1, S2 (Bus Cycle).

    - LOCK .

    - RQ/GT0 (HOLD) RQ/GT1 (HLDA) .

    4.

    / 20 bit. 8086 1 Megabyte . /00000h 0FFFFFh. 1 byte. (segments) 64 kbytes. 16 bytes, /16 . 64 kbytes . (segmentation)

  • 5/24/2018 Assembly [ ]

    8/130

    8

    16 bits 8086. :

    (physical address) 20 bits .

    / / / /. / 8086 :

    . / 16.

    pointer index () , (logical address,

    offset, effective address). / / :

    = * 16 +

    / / :segment:offset segment offset 4 . 987Ah:0100h,CS:IP , DS:9987H ..

    64 kbytes . , :

    CS/(CODE). IP. . CS:IP(PC) .CS =345Ah IP = 712Ch, /:

    CS*10h + IP = 345Ah * 10h + 712Ch = 345A0h + 712Ch = 3B6CCh

    SS /(STACK). / BP. .. SS = 1ABCh SP = 100h,/:

    SS * 10h + SP = 1ABCh * 10h + 100h = 1ABC0h + 100h = 1ACC0h

    DS ES / ( DATA ) ,

    (EXTRA) .

  • 5/24/2018 Assembly [ ]

    9/130

    9

    4 16 bits, () 4 bits /20 bits. /(segment).

    4.

    . , .

    5.-

    1 byte. ( word = 2 bytes )byte /... 3456h , /678h 679h

    5634h :

    /

  • 5/24/2018 Assembly [ ]

    10/130

    10

    /(segment:offset) . . DS=1234h SI=5678h / (pointer) DS:SI 0300h 0303h :

    /

    8086 16 bits. , 512 kbytes / 16 bits . 8086 16 bits

    byte , AD0 BHE. :

    . byte /.AD0 = 0 BHE = 1 ().

    . byte /.AD0 = 1 BHE = 0 ().

    . byte /.AD0 = 0 BHE = 0 ().

    . byte /..

    , High AX A Low B. byte

    byte. ( )

    BA

    .

    ;;

    1 :

    TITLE word__test; DOSSEG

    .MODEL SMALL

    .CODE

  • 5/24/2018 Assembly [ ]

    11/130

    11

    MAIN proc farPUSH DS; DOS, XOR AX,AX; (SEGMENT) PSPPUSH AX; PSP

    MOV AX,@DATA

    MOV DS, AX

    MOV Ah,'A'MOV AL,'B'MOV WORD__LOW__HI,AX; MOV DL,CHAR__low; MOV AH,2INT 21HMOV DL,CHAR__hi; MOV AH,2; 2DOS INT 21H; DOS

    RET; DOS INT 20h PSPMAIN endp

    .DATAWORD__LOW__HI label word

    Char__low db 0Char__hi db 0.STACK 100H

    END MAIN

    6.

    ///64 kbytes. / (port) (DX) byte () /256. (IN OUT). .

  • 5/24/2018 Assembly [ ]

    12/130

    12

    2

    8086 .

    1.

    ASSEMBLY /. (,

    , , ) :

    ,

    (, ,,,..)

    -

    ,

    (1Mbyte RAM ROM)

    / : . (instruction set) . / , (machine language). ASSEMBLY . . :

    add a1,1

  • 5/24/2018 Assembly [ ]

    13/130

    13

    :

    41

    :

    - .-

    .

    - .

    (Assembler)

    . . (TASM.EXE MASM.EXE) .OBJ object module , (TLINK.EXE LINK.EXE) object modules .EXE .COM.

    :

    2 :

    INTDOS EQU 21hTITLE MHNHMAKVDIKAS SEGMENT PUBLICASSUME CS:KVDIKAS,DS:DEDOMENAMAIN PROC NEARmov ax,DEDOMENA ; ds /mov ds,ax ;

    lea dx,mhnhma ; /dxmov ah,9 ; DOS stringint INTDOSMAIN ENDPKVDIKAS ENDSDEDOMENA SEGMENT PUBLICMhnhma db WELLCOME TO ASSEMBLY ,13,10,$DEDOMENA ENDSSOROS SEGMENT PARA STACK SOROS

    Db 100h dup(0) ; 256 bytesSOROS ENDS

    END MAIN

  • 5/24/2018 Assembly [ ]

    14/130

    14

    MHNHMA.ASM,:

    TASMMHNHMA

    , MHNHMA.OBJ. :

    TLINKMHNHMA

    MHNHMA.EXE. .COM , /t(.. TLINK /t ).

    ASSEMBLY

    . :

    ;

    ( labels ) / , . :

    INDOS, KVDIKAS, MAIN, DEDOMENA, MHNHMA, SOROS.

    :.. again .

    again: add a1,5.

    jmp again

    (instructions), (directives)

    . mov, add, int, sub, mul, div..

    EQU, SEGMENT, ENDS, PROC, ENDP, ASSUME, END.

    , , . :

    - ( .. 14, 35d, 21h, 10101000b, 0abcdh) ( . a). d

  • 5/24/2018 Assembly [ ]

    15/130

    15

    , h b.

    - (.ax, bx).- (.jmp again).- LENGTH, OFFSET,:,SEG ..

    assembly () (segments), . STACK. .EXE.

    .COM :

    - ( ). .

    - 256 bytes . 256 bytes (PSPProgram Segment Prefix).

    -. 256 bytes.

    .COM :

    3 :

    TITLE ; CGROUP GROUP KVDIKAS,DEDOMENA ;

    ;

    KVDIKAS SEGMENT PUBLICASSUME CS:CGROUP,DS:CGROUPORG 100h ; 256 .MAIN PROC NEARmov al,aritmos1 ;ALadd al,aritmos2 ; ALmov dl,al ; DL add dl,30h ; ASCII mov ah,2 ; DOS

    int 21h ; DOSint 20h ; DOS .COM

  • 5/24/2018 Assembly [ ]

    16/130

    16

    MAIN ENDPKVDIKAS ENDS

    DEDOMENA SEGMENT PUBLIC

    aritmos1 db 4aritmos2 db 5

    DEDOMENA ENDSEND MAIN

    /t . atroisi.asm, :

    Tlink /t atroisi.obj

    2.

    2.1 END.

    END . .EXE END /. .,ARXH PRAXH :

    4 :

    TITLE AFAIRESH; KVDIKAS SEGMENT PUBLICASSUME CS:KVDIKAS,DS:DEDOMENAPRAXH PROC NEARmov ax,dedomenamov ds,axmov al,aritmos1; 1 ALsub al,aritmos2; ALmov apotelesma,al;

    mov dl,apotelesma; DL 2;DOS

    add dl,30h ; ASCII mov ah,2 ; DOS int 21hret; .PRAXH ENDPARXH PROC NEARcall praxh ; praxhmov ah,4ch ; DOS int 21h ; DOS

    ARXH ENDPKVDIKAS ENDS

  • 5/24/2018 Assembly [ ]

    17/130

    17

    DEDOMENA SEGMENT PUBLICaritmos1 db 4aritmos2 db 3apotelesma db 0

    DEDOMENA ENDS

    SOROS SEGMENT PARA STACK 'SOROS'db 256 dup (0)

    SOROS ENDSEND ARXH

    2.2 ,

    SEGMENTENDS . . SEGMENTENDS(logical segment).

    PROCENDP ., (Calls, Ret) .

    ASSUME . ASSUME CS: .EXE . ASSUME DS: ASSUME ES /,

    (DATA EXTRA) . ASSUME ( labels ) .

    5 :

    TITLE POLLAPLASIAMOS; KVDIKAS SEGMENT PUBLICASSUME CS:KVDIKAS,DS:DEDOMENA1

    PRAXH PROC NEARASSUME DS:DEDOMENA2 ;***** *****

    ;mov ax,dedomena2mov ds,axmov al,aritmos1; 1 ALmov dl,aritmos2; ALmul dl; AL * DL , AXmov apotelesma,al; mov dl,apotelesma;DL

    add dl,30h ; ASCII mov ah,2 ; DOS

  • 5/24/2018 Assembly [ ]

    18/130

    18

    int 21hretPRAXH ENDPARXH PROC NEAR ; call praxh

    ASSUME DS:DEDOMENA1mov ax,dedomena1mov ds,axlea dx,mhnhmamov ah,09hint 21hmov ah,4ch ; DOS int 21h ; DOSARXH ENDPKVDIKAS ENDS

    DEDOMENA1 SEGMENT PUBLICmhnhma db 10,13, "END of PROGRAM",10,13,"$"DEDOMENA1 ENDS

    DEDOMENA2 SEGMENT PUBLICaritmos1 db 4aritmos2 db 2apotelesma db 0

    DEDOMENA2 ENDS

    SOROS SEGMENT PARA STACK "SOROS"Db 256 dup (0)SOROS ENDS

    END ARXH ; /h ARXH

    2.3

    DBbyte, DW , DD , DQDT bytes . DUP

    . . . :

    ARITMOI DW 10,13,29MHNHMA DB HELLOPINAK DB 10 DUP (0)

    21 bytes / :ARITMOI , MHNHMA , PINAK

    . .