1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
.MODEL SMALL
.STACK 128
;---------------------------------------------------------------------------------------------------
; Données
;---------------------------------------------------------------------------------------------------
.DATA
msgfi db "Entrez un nom de fichier: ","$"
msgfin db 10, 13, "Tout c est deroule avec succes","$"
msgerr1 db "Impossible d'ouvrir le fichier specifie","$"
msg db "ok","$"
buf1 db 50 dup (" "),"$";db 10,?,9 dup (0)
newfi db 14,?,13 dup(0)
handel1 dw 50 dup (" "),"$";?
handel2 dw 50 dup (" "),"$";?
buffer dw 50 dup (" "),"$"
buffer2 db 50 dup (" "),"$"
ssi dw ?
sidep dw ?
taille dw ?
;---------------------------------------------------------------------------------------------------
; Code du Programme
;---------------------------------------------------------------------------------------------------
.CODE
debut:
MOV AX,@DATA
MOV DS,AX
MOV ES,AX
;---Demande du nom de fichier
mov ah, 09h
lea dx, msgfi
int 21h
mov ah, 0Ah ;saisie de la chaine lu
lea dx, buf1
int 21h
mov al, buf1
mov newfi, al
lea si, buf1 ;modification de la chaine pour remplacer txt par inv
lea di, newfi
boucle1:
mov al, [si]
mov [di], al
cmp al,'.'
je suite
inc di
inc si
jmp boucle1
suite:
inc di
mov [di], 'i'
inc di
mov [di], 'n'
inc di
mov [di], 'v'
xor bx, bx ;mettre bx à 0
mov bl, byte ptr[newfi+1] ;mettre dans bl le nombre d'octets lus au clavier
mov byte ptr [newfi+2+bx],0
xor bx, bx ;mettre bx à 0
mov bl, byte ptr[buf1+1] ;mettre dans bl le nombre d'octets lus au clavier
mov byte ptr [buf1+2+bx], 0 ;ecrire un 0 deriere le nom de fichier
mov ah, 3Dh ;ouvrir le fichier de depart
lea dx, buf1+2 ;nom du fichier de depart
mov al, 0 ;mode d'acces = lecture seule
int 21h
jc existepas ; si CF=1, le fichier n'existe pas ou est inaccessible
mov handel1, ax ; recuperaton de la taille
MOV AH, 42h
MOV BX, handel1
MOV CX, 0
MOV DX, 0
MOV AL, 2
INT 21h
MOV taille, AX
lea si, buffer2
; mov ah, 09h ;pour tester
; lea dx, [si]
; int 21h
; dec si
lea di, buffer
mov sidep, si
jmp lecture2
existepas:
mov ah, 09h
lea dx, msgerr1
int 21h
jmp fin
lecture2:
mov ah, 3fh
mov bx, handel1
mov cx, taille
lea dx, buffer2
int 21h
jmp lecture2b
lecture:
mov si, ssi
mov sidep, si
inc si
lecture2b:
cmp [si], ' '
je ecriture
cmp [si], '$'
je ecriture2
inc si
jmp lecture2b
ecriture:
mov ssi, si
ecritureb:
mov al, [si]
mov [di], al
cmp sidep, si
je lecture
dec si
inc di
jmp ecritureb
ecriture2:
mov ssi, si
ecriture2b: ;on ecrit buffer2 à l'envers dans buffer =>dec si et inc di
mov al, [si]
mov [di], al
cmp sidep, si
je finecriture
dec si
inc di
jmp ecriture2b
finecriture:
mov al,'$'
mov [di+1], al
lea si, buffer
lea di, handel2
ecrirefichier:
mov ah, 3Ch ;creer le fichier d'arrivee
mov cx, 0
lea dx, newfi+2
mov al, 1 ;mode d'acces = ecriture seule
int 21h
mov handel2, ax
MOV AH, 40h
MOV BX, handel2
MOV CX, taille
LEA DX, buffer ;on ecrit "taille" octets (taille du fichier de depart depuis le debut du buffer
INT 21h
suivant:
mov handel2, ax ; fermeture des 2 fichiers
mov ah, 3Eh
mov bx, handel1
int 21
mov ah, 3Eh
mov bx, handel2
int 21
mov ah, 09h
lea dx, msgfin ;on affiche le message de fin pour dire que tout c 'est bien passé
int 21h
jmp fin
fin:
mov ax, 4C00h ;on rend la main au dos
int 21h
end debut |
Partager