im haveing trouble with this line >> mov [read_len],ax ; returns number of bytes actually
i cant figure out how count up the bytes then put that number in read read_ien
org 100h
section .text
start:
;open test1.txt
mov ah, 3dh ;Open the file
mov al, 0 ;Open for reading
mov dx, filename1 ;Presume DS points at filename
int 21h ; segment.
jc BadOpen
mov [filehnd1], ax ;Save file handle
;read from test1.txt 1 byte at a time into buffer
LP:
mov ah,3fh ;Read data from the file
mov bx, [filehnd1] ;Get file handle value
mov cx, 1
mov dx, textbuf ;Address of data buffer
int 21h
jc ReadError
cmp ax, 0 ;EOF reached?
jne EOF
mov [read_len],ax ; returns number of bytes actually
jmp LP ;Read next byte
EOF:
mov bx, [filehnd1]
mov ah, 3eh ;Close file
int 21h
jc CloseError
;create test2.txt
mov ah,3Ch ; the open/create-a-file function
mov cx,2 ; file attribute - normal file
mov dx,filename2 ; address of a ZERO TERMINATED! filename string
int 021h ; call on Good Old Dos
jc BadOpen
mov [filehnd2],ax ; returns a file handle (probably 5)
;write to test2.txt
mov ah,040h ; write-to-a-file
mov bx,[filehnd2] ; file handle for standard output
mov cx,read_len ; bytes to write - same number we read :)
mov dx,textbuf ; buffer to write from
int 021h ; call on Good Old Dos
;close test2.txt
mov ah,03Eh ; close the file
mov bx,[filehnd2] ; yeah, file handle in bx
int 021h ; call on Good Old Dos
jc CloseError
jmp exit
CloseError:
mov dx,msgclose
mov ah,09
int 21h
xor ax,ax
int 016h
jmp exit
ReadError:
mov dx,msgread
mov ah,09
int 21h
xor ax,ax
int 016h
jmp exit
BadOpen:
mov dx,msgopen
mov ah,09
int 21h
xor ax,ax
int 016h
jmp exit
exit:
mov ah,04Ch ; terminate-program function
int 021h ; you guessed it!
;--------------------------------------------------
section .data
msgclose db "unable to close file...", 0x0d, 0x0a, '$'
msgread db "read error...", 0x0d, 0x0a, '$'
msgopen db "open error...", 0x0d, 0x0a, '$'
filename2 db 'test2.txt',0
filename1 db 'test1.txt',0
;--------------------------------------------------
textbuf times 100 db 0
filehnd1 db 0
filehnd2 db 0
read_len db 0