; CS2011, A Term 1999
; Prof. Sergio A. Alvarez

title File I/O Basics

public open_rfile, open_wfile, read_from_file, write_to_file, close_file

.model small
.stack

.code
.586

open_rfile proc
   mov ax,3d00h  ; DOS function code for read-only file open
   int 21h
   jnc ok_ropen
; insert error handling here
;
   ok_ropen: ret
open_rfile endp

open_wfile proc
   mov ax,3d01h  ; DOS function code for write-only file open
   int 21h
   jnc ok_wopen
; insert error handling here
;
   ok_wopen: ret
open_wfile endp

read_from_file proc
   mov ah,3fh    ; DOS function code for file read
   int 21h
   jnc ok_read
; insert error handling here
;
   ok_read: ret
read_from_file endp

write_to_file proc
   mov ah,40h    ; DOS function code for file write
   int 21h
   jnc ok_write
; insert error handling here
;
   ok_write: ret
write_to_file endp

close_file proc
   mov ah,3eh    ; DOS function code for file close
   int 21h
   jnc ok_close
; insert error handling here
;
   ok_close: ret
close_file endp

end
