JMP Start
cr equ 13h
lf equ 10h
msg1 db 'Cannot Open File, Aborting Program...',cr,lf,'$'
msg2 db 'Cannot Open Output File, Aborting Program...',cr,lf,'$'
msg3 db 'Cannot Write Data to File, Aborting Program...',cr,lf,'$'
msg4 db 'Cannot Reading from File, Aborting Program...',cr,lf,'$'
FileName db 'original.txt',0
OutputFile db 'Output.txt',0
FileHandle1 dw ?
FileHandle2 dw ?
Buffer db ?
Position dw 0
Start:
mov ah,3dh
mov al,0
lea dx,FileName
int 21h
jnc GoodOpen
lea dx,msg1
mov ah,9
int 21h
jmp PgmExit
GoodOpen:
mov FileHandle1,ax
mov ah,3ch
mov cx,0
lea dx,OutputFile
int 21h
jnc GoodOpen2
lea dx,msg2
mov ah,9
int 21h
mov ah,3eh
mov bx,FileHandle1
int 21h
jmp PgmExit
GoodOpen2:
mov FileHandle2, ax
ReadFileLP:
mov bx,FileHandle1
mov cx,1
lea dx,Buffer
mov ah,3Fh
int 21h
jc BadRead
cmp ax,1
jz ReadOK
jmp AtEOF
ReadOK:
mov al,Buffer
cmp al,cr
jb NotLower
cmp al,lf
ja LineNo
mov al, 5fh
NotLower:
mov Buffer,al
mov bx,FileHandle2
mov cx,1
lea dx,buffer
mov ah,40h
int 21h
jc BadWrite
cmp ax,1
jz ReadFileLP
LineNo:
;here is the line number stuff
BadWrite:
lea dx,msg3
mov ah,9
int 21h
jmp AtEOF
BadRead:
lea dx,msg4
mov ah,9
int 21h
AtEOF:
mov bx,FileHandle1
mov ah,3eh
int 21h
mov bx,FileHandle2
mov ah,3eh
int 21h
PgmExit:
mov ah,4ch
int 21h