Guida all'assembler



Partiamo con il codice del programma
            ;cdr     9:0000
;00,08,03,00  segmento impostazioni
;00,08,03,80  segmento codice
;22:0000      elenco archivi
;24:0000      buffer comandi
;25:0000      buffer del cdr
      jmp 0000
      jmp 0004
*00 00        ;0006 porta 174,175
*000000000000000000000000 ;0008 porta 170
*00 00 00 00  ;0014 settore in lettura
*00 00 00 00  ;0018 traccia in scrittura
*00 00 00 00  ;001c settore in scrittura
*c8 14 05 00  ;0020 max settore cdr
*01 00        ;0024 numero pagina
*00 00        ;0026
*00 00 00 00  ;0028 memoria video corrente
*00 00 25 00  ;002c buffer del cdr
*00 00 26 00  ;0030 prossimo archivio
*00 00 00 00  ;0034 blocco in lettura
:0001 push edi ;call inutile****************
      push cx
      lea edi,00000000
      mov cx,8000
:0003 add di,0002
      dec cx
      jz 0002
      mov ax,[edi]
      cmp ax,FFFF
      jnz 0003
:0002 pop cx
      pop edi
      ret
:0004 push ax ;int 17******************
      call 0001
      cli
      mov al,20
      out 20,al
      call 0001
      sti
      pop ax
      iretd
:0005 push dx ;avvio comandi***************
      mov dx,0176
      mov al,A0
      out dx,al
      inc dx
:0006 call 0001
      in al,dx
      test al,80
      jnz 0006
      mov dx,0376
      mov al,08
      out dx,al
      mov dx,0171
      mov al,00
      out dx,al
      inc dx
      out dx,al
      inc dx
      out dx,al
      inc dx
      mov al,[00090006]  ;porta 174
      out dx,al
      inc dx
      mov al,[00090007]  ;porta 175
      out dx,al
      mov dx,0177
      mov al,A0
      out dx,al
:0007 call 0001
      in al,dx
      and al,88
      cmp al,08
      jnz 0007
      pop dx
      ret
:0008 push esi ;comandi*******************
      push ecx
      push dx
      lea esi,00090008
      mov ecx,00000003
      cli
      mov dx,0170
      repz
      outsd
      mov dx,0177
:0009 call 0001
      in al,dx
      test al,80
      jnz 0009
      sti
      xor eax,eax
      mov [00090008],eax
      mov [0009000C],eax
      mov [00090010],eax
      in al,dx
      pop dx
      pop ecx
      pop esi
      ret
:000b push edi ;ritira i dati****************
      push ecx
      push dx
      xor ecx,ecx
      lea edi,00240000   ;buffer
      mov dx,0175
      in al,dx
      mov ah,al
      dec dx
      in al,dx
      mov cx,ax
      shr cx,02
      cli
      mov dx,0170
      repz
      insd
      mov dx,0177
:000c call 0001
      in al,dx
      test al,80
      jnz 000C
      sti
      pop dx
      pop ecx
      pop edi
      ret
:0017 push ecx ;invia i dati*****************
      push dx
      xor ecx,ecx
      mov dx,0175
      in al,dx
      mov ah,al
      dec dx
      in al,dx
      mov cx,ax
      shr cx,02
      cli
      mov dx,0170
      repz
      outsd
      mov dx,0177
:0018 call 0001
      in al,dx
      test al,80
      jnz 0018
      sti
      pop dx
      pop ecx
      ret
:001d cmp [esi],39 ;spazio*****************
      jnz 001E
      inc si
      jmp 001D
:001e ret
:001f push esi ;stampa la pagina****************
      push ebx
      push ecx
      mov edi,[00010248]
      mov eax,[00010240]
      mov ecx,00000018
      mul ecx
      add edi,eax
      mov [00090028],edi
      mov bx,0009        ;colore
      mov ebp,esi
      mov dl,00          ;ciclo in verticale
:0026 push edi
      cmp dl,24
      jz 0020
      mov dh,32
      mov al,1C
      callf 0008:0016
      add edi,00000008
:0022 mov al,[esi]       ;ciclo sulla riga
      cmp al,00
      jz 0020
      cmp al,FF
      jz 0021
      callf 0008:0016
      add edi,00000008
      inc si
      dec dh
      jmp 0022
:0021 callf 0008:0016    ;stampa il numero
      add edi,00000008
      push esi
      mov eax,[esi+01]
      lea esi,001013B0
      mov cx,0004
      callf 0008:001C
      lea si,13B0
      mov cx,0008
:0023 mov al,[esi]
      callf 0008:0016
      add edi,00000008
      inc si
      dec dh
      loop 0023
      pop esi
:0025 cmp dh,00
      jz 0024
      mov al,1C
      callf 0008:0016
      add edi,00000008
      dec dh
      jmp 0025
:0024 pop edi
      mov eax,[00010240]
      shl eax,04
      add edi,eax
      add si,0005
      inc dl
      jmp 0026
:0020 pop edi
      mov dh,01
      push dx            ;coordinata verticale
      mov dh,00
      sub dx,0024
      neg dx
      shl dx,04
      lea esi,000A0000   ;pulisce la pagina
:0031 cmp dx,0000
      jz 0027
      push edi
      mov si,di
      callf 0008:0015
      mov eax,FFFFFFFF
      mov cx,0068
:0030 mov [esi],eax
      add si,0004
      jnz 002F
      add edi,00010000
      callf 0008:0015
:002f loop 0030
      pop edi
      add edi,[00010240]
      dec dx
      jmp 0031
:0027 pop dx
      pop ecx
      pop ebx
      pop esi
      ret
:0032 push esi ;imposta la pagina***************
      push edi
      push ebx
      push cx
      mov bx,030F        ;colore
      xor eax,eax
      mov ax,[00090024]
      callf 0008:002A
      mov esi,edi
      mov edi,[00010248]
      mov eax,[00010240]
      shl eax,02
      add eax,00000040
      add edi,eax
      mov cx,0004
:0033 mov al,[esi]
      callf 0008:0016
      add edi,00000008
      inc si
      loop 0033
      pop cx
      pop ebx
      pop edi
      pop esi
      ret
:0034 push esi ;xor sul nome*****************
      push cx
      push dx
      mov edi,[00090028]
      add edi,00000008
      mov esi,ebp
      mov cx,0000
:0035 add cx,0002
      inc si
      cmp [esi],FF
      jnz 0035
      lea esi,000A0000
      mov dl,10
:0038 mov si,di
      callf 0008:0015
      push edi
      push cx
:0037 xor [esi],04040404
      add si,0004
      jnz 0036
      add edi,00010000
      callf 0008:0015
:0036 loop 0037
      pop cx
      pop edi
      add edi,[00010240]
      dec dl
      jnz 0038
      pop dx
      pop cx
      pop esi
      ret
:0039 push cx ;inizio pagina******************
      push dx
      lea esi,00220000
      dec ax
      mov cx,0024
      mul cx
:003c cmp ax,0000
      jz 003A
:003b inc si
      cmp [esi],FF
      jnz 003B
      add si,0005
      cmp [esi],00
      jz 003A
      dec ax
      jmp 003C
:003a cmp ax,0000
      pop dx
      pop cx
      ret
:003d inc bp ;prossima riga****************
      cmp [ebp+00],FF
      jnz 003D
      add bp,0005
      ret
:003e push dx ;riga indietro***************
      sub bp,0006
:0042 dec bp
      jz 003F
      cmp [ebp+00],FF
      jnz 0042
      add bp,0005
:003f pop dx
      ret
:0043 push esi ;traccia numero************
      push edi
      push ebx
      push cx
      mov ch,01
      mov cl,[00090018]
:0048 mov eax,[00090018]
      callf 0008:002A
      mov esi,edi
      mov edi,[00010230]
      mov bx,030F        ;colore
:0045 mov al,[esi]
      callf 0008:0016
      add edi,00000008
      inc si
      mov al,[esi]
      callf 0008:0016
:0044 mov ax,[00010210]  ;ciclo tastiera
      cmp al,00
      jz 0044
      mov [00010210],0000
      cmp ax,E02A
      jz 0044
      cmp al,4E
      jz 0046
      cmp al,4A
      jz 0047
      pop cx
      pop ebx
      pop edi
      pop esi
      ret
:0046 cmp cl,[00090018]  ;incrementa
      jz 0044
      inc [00090018]
      jmp 0048
:0047 cmp ch,[00090018]  ;decrementa
      jz 0044
      dec [00090018]
      jmp 0048
:0049 push ebp ;blocco numero******************
:004a inc bp
      cmp [ebp+00],FF
      jnz 004A
      mov eax,[ebp+01]
      mov [00090034],eax
      pop ebp
      ret
:004b push ecx ;lettuta cdr************
      push dx
      xor ecx,ecx
      mov cx,0020
      cli
:004d push cx
      mov dx,0170
      mov cx,0200
      repz
      insd
      mov dx,0177
:004c call 0001
      in al,dx
      test al,80
      jnz 004C
      pop cx
      loop 004D
      sti
      pop dx
      pop ecx
      ret
jmpf 0008:001E
:0000 mov ax,0001        ;inizio codice*********************
:000f mov al,28          ;lettura cdr+++++++++++++++
      mov [00090008],al
      xor eax,eax
      mov [0009000A],eax
      mov al,01
      mov [00090010],al
      mov ax,0800
      mov [00090006],ax
      call 0005
      call 0008
      cmp al,58
      jz 000A
      mov al,03          ;errore in lettura
      mov [00090008],al
      mov ax,0010
      mov [0009000C],ax
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      mov al,[0024000C]
      cmp al,3A
      jz 000D
      cmp al,04
      jz 0010
      cmp al,64
      jz 0012
      cmp al,28
      jz 0014
jmpf 0008:001E
:000d callf 0008:0091    ;Inserire il disco-----------
      lea esi,00101A00
      callf 0008:007E
      mov eax,[00010208]
      add eax,00000080
      mov ecx,eax
:000e call 0001
      mov eax,[00010208]
      cmp eax,ecx
      jb 000E
      jmp 000F
:0010 callf 0008:0091    ;Disco in rotazione----------
      lea esi,00101A12
      callf 0008:007E
      mov eax,[00010208]
      add eax,00000040
      mov ecx,eax
:0011 call 0001
      mov eax,[00010208]
      cmp eax,ecx
      jb 0011
      jmp 000F
:0012 callf 0008:0091    ;Il disco č vuoto------------
      lea esi,00101A25
      callf 0008:007E
      mov eax,[00010208]
      add eax,00000020
      mov ecx,eax
:0013 call 0001
      mov eax,[00010208]
      cmp eax,ecx
      jb 0013
      jmp 0015
:0014 callf 0008:0091    ;Disco in lettura-----------
      lea esi,00101A36
      callf 0008:007E
      jmp 000F
:000a call 000B          ;ritira i dati+++++++++++++++
      mov al,51          ;informazione disco
      mov [00090008],al
      mov ax,000C
      mov [00090010],al
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      mov ah,[0024000B]
      mov al,[00240006]
      mov [00090018],ax  ;traccia in scrittura
      mov al,52          ;informazione traccia
      mov [00090008],al
      mov al,01
      mov [00090009],al
      mov ax,[00090018]
      xchg ah,al
      mov [0009000C],ax
      mov ax,001C
      mov [00090010],al
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      mov eax,[00240010]
      bswap eax
      mov [00090020],eax ;blocchi rimasti
      mov eax,[0024000C]
      bswap eax
      mov [0009001C],eax ;settore in scrittura
      mov al,52          ;informazione blocco
      mov [00090008],al
      mov al,01
      mov [00090009],al
      mov ax,[00090018]
      dec ax
      xchg ah,al
      mov [0009000C],ax
      mov ax,001C
      mov [00090010],al
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      mov eax,[00240008]
      bswap eax
      mov [00090014],eax ;settore in lettura
:0015 mov al,1E          ;blocca lo sportello
      mov [00090008],al
      mov al,01
      mov [0009000C],al
      mov ax,0000
      mov [00090006],ax
      call 0005
      call 0008
:0019 callf 0008:0091    ;linea di comando+++++++++++++
:001a mov ax,[00010210]  ;ciclo tastiera
      cmp al,00
      jz 001A
      mov [00010210],0000
      cmp ax,E02A
      jz 001A
      cmp al,0E
      jz 001B
      cmp al,1C
      jz 001C
      mov ebx,[0001022C] ;carattere
      cmp bx,1400
      jz 001A
      mov [ebx],al
      inc bx
      mov [0001022C],bx
      mov edi,[00010230]
      mov bx,030F        ;colore
      callf 0008:0016
      add edi,00000008
      mov [00010230],edi
      jmp 001A
:001b mov ebx,[0001022C] ;cancella
      cmp bx,13C0
      jz 001A
      dec bx
      mov [ebx],00
      mov [0001022C],bx
      mov edi,[00010230]
      mov bx,0E0E        ;colore
      sub edi,00000008
      callf 0008:0016
      mov [00010230],edi
      jmp 001A
:001c mov edi,[00010230] ;ritorno
      mov bx,010F        ;colore
      mov al,A8
      callf 0008:0016
      lea esi,001013C0
      cmp [esi],2E
      jz 0041
      inc si
      cmp [esi],17
      jnz 0019
      inc si
      inc si
      inc si
      inc si
      mov ax,0001 ;disco***********************************
      mov [00090024],ax
      mov eax,00250000
      mov [0009002C],eax
      mov [00090030],eax
      mov ebx,[0009001C]
      add ebx,00000020
      lea esi,00220000
      call 001F
      call 0032
      call 0034
:0028 mov ax,[00010210]  ;ciclo tastiera++++++++++++++++
      cmp al,00
      jz 0028
      mov [00010210],0000
      cmp ax,E02A
      jz 0028
      cmp ax,E051
      jz 0029
      cmp ax,E049
      jz 002A
      cmp ax,E050
      jz 002B
      cmp ax,E048
      jz 002C
      cmp ax,E037
      jz 000F
      cmp al,1C
      jz 002D
      cmp al,01
      jz 002E
      cmp al,3B
      jz 0016
      jmp 0028
:0029 mov ax,[00090024] ;pagina in gių
      inc ax
      call 0039
      jnz 0028
      incw [00090024]
      call 001F
      call 0032
      call 0034
      jmp 0028
:002a mov ax,[00090024]  ;pagina sų
      cmp al,01
      jz 0028
      decw [00090024]
      call 0039
      call 001F
      call 0032
      call 0034
      jmp 0028
:002b cmp dh,dl          ;riga in basso
      jz 0028
      inc dh
      call 0034
      call 003D
      mov eax,[0001024C]
      add [00090028],eax
      call 0034
      jmp 0028
:002c cmp dh,01          ;riga in alto
      jz 0028
      dec dh
      call 0034
      call 003E
      mov eax,[0001024C]
      sub [00090028],eax
      call 0034
      jmp 0028
:002d push edi           ;copia archivi
      push ebp
      mov edi,[0009002C]
:0050 mov al,[ebp+00]
      mov [edi],al
      inc bp
      inc di
      cmp al,FF
      jnz 0050
      mov eax,[ebp+00]
      mov [00010218],eax
      mov [edi],ebx
      add di,0004
      mov [0009002C],di
      mov ax,0080
      mov [00010214],ax
      mov edi,[00090030]
      add edi,00010000
      mov [0001021C],edi
      mov [00090030],edi
      callf 0008:000D    ;primo archivio
      add ebx,00000020
      add di,0100
:0052 add di,0004
      mov eax,[edi]
      cmp eax,00000000
      jz 0051
      mov [00010218],eax
      mov eax,[00090030]
      add eax,00010000
      mov [0001021C],eax
      mov [00090030],eax
      callf 0008:000D    ;archivi seguenti
      add ebx,00000020
      jmp 0052
:0051 pop ebp
      pop edi
      jmp 0028
:002e mov ax,[0009002C]  ;copia su cdr+++++++++++++++
      cmp ax,0000
      jz 0028
      mov al,[00090018]
      cmp al,FF
      jz 0040
      mov edi,[0009002C]
      xor eax,eax
      mov [edi],eax
      callf 0008:0091    ;scrittura del cdr===============
      lea esi,00101A9C
      callf 0008:007E
      mov eax,[00090020]
      cmp eax,ebx
      jb 0040
      mov al,5A          ;mode sense-------------
      mov [00090008],al
      mov al,08
      mov [00090009],al
      mov al,05
      mov [0009000A],al
      mov ax,003C
      mov [00090006],ax
      xchg ah,al
      mov [0009000F],ax
      call 0005
      call 0008
      call 000B
      lea esi,00240000
;      mov al,11          ;scrittura modo test
;      mov [esi+0A],al
      mov al,55          ;mode select------------
      mov [00090008],al
      mov al,10
      mov [00090009],al
      mov ax,003C
      mov [00090006],ax
      xchg ah,al
      mov [0009000F],ax
      call 0005
      call 0008
      call 0017
      lea esi,00250000   ;buffer del cdr
      mov eax,[0009001C]
      sub ebx,eax        ;totale blocchi
:0054 mov al,2A          ;srittura cdr-------------
      mov [00090008],al
      mov eax,[0009001C]
      bswap eax
      mov [0009000A],eax
      mov [0009000F],bh
      mov [00090010],bl
      mov ax,0800
      mov [00090006],ax
      call 0005
      call 0008
      cmp al,51
      jz 000F
:0053 call 0017
      cmp al,58
      jz 0053
      cmp al,50
      jnz 0054
      mov al,35          ;svuota la cache----------
      mov [00090008],al
      mov ax,0000
      mov [00090006],ax
      call 0005
      call 0008
      mov al,5B          ;chiude la traccia----------
      mov [00090008],al
      mov al,01
      mov [0009000A],al
      mov [0009000D],al
      mov ax,0000
      mov [00090006],ax
      call 0005
      call 0008
      mov ax,[00090018]
      cmp ax,0000
      jnz 0055
      incw [0013001C]    ;disco numero
      inc ax
:0055 mov [0013001E],ax  ;traccia in scrittura
      mov ax,0001
      mov [00010214],ax
      mov eax,00080300
      mov [00010218],eax
      mov eax,00130000
      mov [0001021C],eax
      callf 0008:0096    ;salva la traccia
      jmp 000F
jmpf 0008:001E
:0041 inc si ;cdr******************************************
      cmp [esi],20
      jnz 0019
      inc si
      inc si
      callf 0008:0091
      lea esi,00101710
      callf 0008:007E
      dec [00090018]
      call 0043
      mov al,52          ;informazione blocco----------
      mov [00090008],al
      mov al,01
      mov [00090009],al
      mov ax,[00090018]
      xchg ah,al
      mov [0009000C],ax
      mov ax,001C
      mov [00090010],al
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      mov eax,[00240008]
      bswap eax
      mov [00090014],eax
      lea esi,00250000   ;buffer del cdr
      mov dx,0001        ;totale blocchi
:0057 mov al,28          ;lettura elenco++++++++++++++
      mov [00090008],al
      mov eax,[00090014]
      bswap eax
      mov [0009000A],eax
      mov al,01
      mov [00090010],al
      mov ax,0800
      mov [00090006],ax
      call 0005
      call 0008
      call 000B
      lea edi,00240000   ;sposta i dati
      mov cx,0200
:0056 mov eax,[edi]
      mov [esi],eax
      add si,0004
      add di,0004
      loop 0056
      incd [00090014]
      dec dx
      jnz 0057
      mov ax,0001
      mov [00090024],ax
      lea si,0000
      call 001F
      call 0032
      call 0034
:0058 mov ax,[00010210]  ;ciclo tastiera++++++++++++++++
      cmp al,00
      jz 0058
      mov [00010210],0000
      cmp ax,E02A
      jz 0058
      cmp ax,E051
      jz 0059
      cmp ax,E049
      jz 005A
      cmp ax,E050
      jz 005B
      cmp ax,E048
      jz 005C
      cmp ax,E037
      jz 000F
      cmp al,3C
      jz 005D
      cmp al,3D
      jz 005E
      cmp al,3B
      jz 0016
      jmp 0058
:0059 mov ax,[00090024] ;pagina in gių
      inc ax
      call 0039
      jnz 0058
      incw [00090024]
      call 001F
      call 0032
      call 0034
      jmp 0058
:005a mov ax,[00090024]  ;pagina sų
      cmp al,01
      jz 0058
      decw [00090024]
      call 0039
      call 001F
      call 0032
      call 0034
      jmp 0058
:005b cmp dh,dl          ;riga in basso
      jz 0058
      inc dh
      call 0034
      call 003D
      mov eax,[0001024C]
      add [00090028],eax
      call 0034
      jmp 0058
:005c cmp dh,01          ;riga in alto
      jz 0058
      dec dh
      call 0034
      call 003E
      mov eax,[0001024C]
      sub [00090028],eax
      call 0034
      jmp 0058
:005d push esi           ;Copia su disco++++++++++++
      push edi           ;tasto F2
      push dx
      lea edi,00260000
      lea esi,00260100
      call 0049
      mov ax,0080
      mov [00010214],ax
:005f mov al,28          ;lettura archivio
      mov [00090008],al
      mov eax,[00090034]
      bswap eax
      mov [0009000A],eax
      mov al,20
      mov [00090010],al
      mov ax,0800
      mov [00090006],ax
      call 0005
      call 0008
      call 004B
      mov dx,0177
      in al,dx
      cmp al,50
      jnz 0100
      mov eax,[esi]
      mov [00010218],eax
      mov eax,edi
      sub eax,00010000
      mov [0001021C],eax
      callf 0008:0096    ;sposta l'archivio su disco
      mov eax,00000020
      add [00090034],eax
      add si,0004
      mov eax,[esi]
      cmp eax,00000000
      jnz 005F
      pop dx
      pop edi
      pop esi
      jmp 0058
jmpf 0008:001E
:005e push esi           ;Copia su disco++++++++++++
      push edi           ;tasto F3
      push dx
      mov ax,0001
      mov [00010214],ax
      mov eax,00081600   ;segmento di copia
      mov [00010218],eax
      mov eax,00004000
      mov [0001021C],eax
      callf 0008:000D
      lea ebx,00004100
      lea edi,00260000
      lea esi,00260100
      call 0049
      mov ax,0080
      mov [00010214],ax
:0060 mov al,28          ;lettura archivio
      mov [00090008],al
      mov eax,[00090034]
      bswap eax
      mov [0009000A],eax
      mov al,20
      mov [00090010],al
      mov ax,0800
      mov [00090006],ax
      call 0005
      call 0008
      call 004B
      mov dx,0177
      in al,dx
      cmp al,50
      jnz 0100
      mov eax,[ebx]
      mov [00010218],eax
      mov eax,edi
      sub eax,00010000
      mov [0001021C],eax
      callf 0008:0096    ;sposta l'archivio su disco
      mov eax,00000020
      add [00090034],eax
      add bx,0004
      add si,0004
      mov eax,[esi]
      cmp eax,00000000
      jnz 0060
      mov eax,[00260000] ;fondo archivio
      mov [00004000],eax
      mov ax,0001        ;salva il primo settore
      mov [00010214],ax
      mov eax,00081600
      mov [00010218],eax
      mov eax,00004000
      mov [0001021C],eax
      callf 0008:0096
      pop dx
      pop edi
      pop esi
      jmp 0058
jmpf 0008:001E
:0040 callf 0008:0091    ;Nessuna copia+++++++++++++++
      lea esi,00101A62
      callf 0008:007E
:0016 mov al,1E          ;sblocca lo sportello
      mov [00090008],al
      mov ax,0000
      mov [00090006],ax
      call 0005
      call 0008
      mov al,1B          ;apre lo sportello
      mov [00090008],al
      mov al,02
      mov [0009000C],al
      mov ax,0000
      mov [00090006],ax
      call 0005
      call 0008
:0100
jmpf 0008:001e
      


Introduzione alla programmazione in "Assembler"
invia E-mail