Untitled
unknown
assembly_x86
3 years ago
2.0 kB
41
Indexable
.model small
.stack 100h
.data
file_name db "input.txt", 0
output_name db "output.txt", 0
new_word db "new_word", 13, 10, "$"
file_hand dw 0
output_file_hand dw 0
counter db 0
buffer db 1 dup(0), "$"
buffer2 db 10 dup(0), "$"
.code
Pradzia:
mov ax, @data
mov ds, ax
open_file:
mov ah, 3dh ; opening file
mov al, 0
mov dx, offset file_name
int 21h
mov file_hand, ax
open_output_file:
mov ah, 3ch
mov cx, 0
mov dx, offset output_name
int 21h
mov output_file_hand, ax
reading:
mov bx, file_hand
mov ah, 3fh
mov al, 0
mov cx, 1
mov dx, offset buffer
int 21h
mov file_hand, bx ; updating file_hand
checking:
mov al, ds:[buffer]
cmp al, 77h ; comparing to letter 'w'
je reading_word
jmp printing_symbol
jmp reading
reading_word: ; checks if 3 continuing bytes make "word"
mov bx, file_hand
mov ah, 3fh
mov al, 0
mov cx, 3
mov dx, offset buffer2
mov file_hand, bx ; updating file_hand
mov al, ds:[buffer2 + 1]
cmp al, 6fh ; comparing to letter 'o'
inc counter
mov al, ds:[buffer2 + 2]
cmp al, 72h ; comparing to letter 'r'
inc counter
mov al, ds:[buffer2 + 3]
cmp al, 64h ; comparing to letter 'd'
inc counter
;if "word" found
cmp counter, 3
je printing_string
jmp reading
exit:
mov ax, 3eh ; closing files
mov bx, file_hand
int 21h
mov ax, 3eh
mov bx, output_file_hand
int 21h
mov ah, 4ch
int 21h
printing_string:
mov cx, ax ;STRING LENGTH.
mov ah, 40h
mov bx, output_file_hand
mov dx, offset new_word
int 21h
mov output_file_hand, bx
ret
printing_symbol:
mov cx, 1
mov ah, 40h
mov bx, output_file_hand
mov dx, offset buffer
int 21h
mov output_file_hand, bx
ret
end PradziaEditor is loading...