Write an assembly program that opens each file in a directory and then changes all of the occurences of foo with bar.<p>;Open a file handle<p>mov ax, 3Dh<p>mov dx, offset filename<p>int 21h<p>;Check that the file handle is valid<p>cmp ax, 0<p>jne file_open<p>;Start looping through the directory<p>mov si, offset directory<p>mov di, offset filename<p>loop:<p>mov al, [si]<p>cmp al, 0<p>je exit<p>;Copy the filename<p>mov [di], al<p>inc si<p>inc di<p>jmp loop<p>file_open:<p>;Read the file and search for "foo"<p>mov bx, ax<p>mov ah, 3Fh<p>mov cx, 0FFFFh<p>mov dx, offset buffer<p>int 21h<p>;Check if the end of file has been reached<p>cmp ax, 0<p>je exit<p>;Loop through the read buffer<p>mov si, offset buffer<p>mov di, offset replace<p>loop2:
mov al, [si]
cmp al, 'f'
je check_foo
inc si
jmp loop2<p>check_foo:
cmp byte [si + 1], 'o'
jne loop2
cmp byte [si + 2], 'o'
jne loop2<p>;Replace "foo" with "bar"
mov [di], 'b'
inc di
mov [di], 'a'
inc di
mov [di], 'r'
inc di
jmp loop2<p>;Write the modified buffer to the file
mov bx, ax
mov ah, 40h
mov cx, 0FFFFh
mov dx, offset replace
int 21h<p>;Go to the next file
jmp file_open<p>exit:
;Close the file
mov ah, 3Eh
int 21h<p>;Exit
mov ax, 4C00h
int 21h