Hi, this program has to reverse the text in file. It uses two buffers of 100 bytes. One for reading piece of text, next for reversing that text.I tested program with file which contains of 120 bytes of numbers. I run debbuger and see, that symbols are reversed corertly in buffer and first to 100bytes are rewritten corectly. I see that when i open text file. Then other 20 bytes are reversed corretly, but when writing them something goes wrong and symbols in text become damaged. Can anybody help me, i am debugging this program for a week and can not make it work in the right way
ASSUME CS:Kodas, DS:Duom, SS:Stekas
;buferioDydis EQU 121
Stekas SEGMENT PARA STACK 'STACK'
DB 256 dup (?)
Stekas ENDS
duom segment
file db 13 dup (0)
handle dw ?
buffer1 db 100 dup (0)
buffer2 db 100 dup (0)
msg1 db 10, 13, "PSP is empty", '$'
msg2 db 10, 13, "Only spaces found in psp", '$'
msg3 db 10, 13, "Name of file is too long", '$'
er1 db 10, 13, "error in opening the file", "$"
er2 db 10, 13, "error in reading the file", "$"
er3 db 10, 13, "error in writting the file", "$"
er4 db 10, 13, "error in moving file pointer", "$"
msg4 db 10, 13, "Done", "$"
var dw ?
duom ends
kodas segment
start:
mov ax, duom
mov ds, ax
mov ax, 02h ;clear screen
int 10h
xor si, si
mov si, 80h
xor cx, cx
mov cl, es:[si]
cmp cl, 0 ;if length of psp=0, finish work
je message1
jmp continue
message1:
mov dx, offset msg1
mov ah, 9
int 21h
jmp endprogram
continue:
xor di, di
mov di, offset file ;initializing buffer for the file name
xor cx, cx
skipspaces:
inc si ; skipping spaces in psp
mov al, es:[si]
cmp al, ' '
je skipspaces
filename:
mov [di], al ;getting file name
inc di
inc cx
inc si
mov al, es:[si]
cmp al, ' '
je continue2
cmp al, 0Dh ;if the end of psp, finish the program
je continue2
jmp filename
continue2:
mov [di], byte ptr 0 ;marking the end of the name with zero
cmp cl, 0
je message2 ;if only spaces found, finish program
cmp cl, 12
jg message3 ;if only spaces found, finish program
jmp continue3
message2:
mov dx, offset msg2
mov ah, 9
int 21h
jmp endprogram
message3:
mov dx, offset msg3
mov ah, 9
int 21h
jmp endprogram
continue3:
xor bx, bx
xor ax, ax
mov ah, 3Dh
mov al, 2
mov dx, [di] ; opening file
int 21h
jc error1
mov handle, ax
jmp reading
error1:
mov dx, offset er1
mov ah, 9
int 21h
jmp endprogram
reading:
xor bx, bx
xor ah, ah
mov ah, 3Fh
mov cx, 100 ;reading 100 bytes to buffer
mov dx, offset buffer1
mov bx, handle
int 21h
jc error2
mov var, ax
mov ah, 42h ;Seek command
mov al, 1 ;Move from current location
xor cx, cx ;Zero out CX and DX so we
xor dx, dx ; stay right here
mov bx, Handle
int 21h
jc error4
jmp continue4
error2:
mov dx, offset er2
mov ah, 9
int 21h
jmp endprogram
continue4:
xor al, al ;now reversing the text using buffer2
xor di, di
xor si, si
mov si, 99
mov al, buffer1[si]
cmp al, 00h
je cycle
cmp al, 20h
je ciklas
mov buffer2[di],
al
cycle:
dec si
mov al, buffer1[si]
cmp al, 00h
je cycle
cmp al, 20h
je cycle
inc di
mov buffer2[di], al
cmp si, 0
je movepointer
jmp cycle
movepointer:
mov ah, 42h ;Seek command
mov al, 1 ;Move from current location
xor cx, cx ;Zero out CX and DX so we
xor dx, dx ; stay right here
mov bx, Handle
int 21h
jc error4
sub ax, var ;DX:AX now contains the
sbb dx, 0 ; current file position, so
mov cx, dx ; compute a location 256
mov dx, ax ; bytes back.
mov ah, 42h
mov al, 0 ;Absolute file position
int 21h ;BX still contains handle.
jc error4
jmp writting
error3:
mov dx, offset er3
mov ah, 9
int 21h
jmp end program
writting:
xor ax, ax
mov ah, 40h
mov bx, handle
mov cx, var ;writing content of buffer2 to file
mov dx, offset buffer2
int 21h
jc error3
mov ah, 42h ;Seek command
mov al, 1 ;Move from current location
xor cx, cx ;Zero out CX and DX so we
xor dx, dx ; stay right here
mov bx, Handle
int 21h
jc error4
jmp continue5
continue5:
cmp var, 100
jl endprogram
mov var, 0
xor si, si ;before reading next 100 bytes clear buffers
mov buffer1[si], 0
mov buffer2[si], 0
cycle3:
inc si
mov buffer1[si], 0
mov buffer2[si], 0
cmp si, 99
jl cycle3
xor cx, cx
xor bx, bx
xor ax, ax
jmp reading
error4:
mov dx, offset er4
mov ah, 9
int 21h
jmp endprogram
endprogram:
xor ax, ax
xor bx, bx
mov ah, 3Eh
mov bx, handle
int 21h
mov dx, offset msg4
mov ah, 9
int 21h
mov ah, 07h
int 21h
mov ax, 4c00h
int 21h
kodas ends
end start