home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / dos_ency / 7 / openfile.asm < prev    next >
Encoding:
Assembly Source File  |  1988-08-11  |  1.9 KB  |  47 lines

  1. kbuf    db      64,0,64 dup (0)
  2. prompt  db      0dh,0ah,'Enter filename: $'
  3. myfcb   db      37 dup (0)
  4.  
  5.         .
  6.         .
  7.         .
  8.                                 ; display the prompt...
  9.         mov     dx,seg prompt   ; DS:DX = prompt address
  10.         mov     ds,dx
  11.         mov     es,dx
  12.         mov     dx,offset prompt
  13.         mov     ah,09H          ; Function 09H = print string
  14.         int     21h             ; transfer to MS-DOS
  15.  
  16.                                 ; now input filename...
  17.         mov     dx,offset kbuf  ; DS:DX = buffer address
  18.         mov     ah,0ah          ; Function 0AH = enter string
  19.         int     21h             ; transfer to MS-DOS
  20.  
  21.                                 ; parse filename into FCB...
  22.         mov     si,offset kbuf+2 ; DS:SI = address of filename
  23.         mov     di,offset myfcb ; ES:DI = address of fcb
  24.         mov     ax,2900h        ; Function 29H = parse name
  25.         int     21h             ; transfer to MS-DOS
  26.         or      al,al           ; jump if bad drive or
  27.         jnz     error           ; wildcard characters in name
  28.  
  29.                                 ; try to open file...
  30.         mov     dx,offset myfcb ; DS:DX = FCB address
  31.         mov     ah,0fh          ; Function 0FH = open file
  32.         int     21h             ; transfer to MS-DOS
  33.         or      al,al           ; check status 
  34.         jz      proceed         ; jump if open successful
  35.  
  36.                                 ; else create file...
  37.         mov     dx,offset myfcb ; DS:DX = FCB address
  38.         mov     ah,16h          ; Function 16H = create
  39.         int     21h             ; transfer to MS-DOS
  40.         or      al,al           ; did create succeed?
  41.         jnz     error           ; jump if create failed
  42.  
  43. proceed:
  44.         .                       ; file has been opened or
  45.         .                       ; created, and FCB is valid
  46.         .                       ; for read/write operations...
  47.