1 / 9

File I/O Services

File I/O Services. (3Ch) Create File (3Dh) Open File (3Eh) Close File (3Fh) Read from File or Device (40h) Write to File or Device. 3Dh Open File. Three File Modes (Stored in AL) 0 – Input (Read Only) 1 – Output (Write Only) 2 – Input/Output Error Codes (CF=1, AX holds codes)

tassos
Download Presentation

File I/O Services

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. File I/O Services • (3Ch) Create File • (3Dh) Open File • (3Eh) Close File • (3Fh) Read from File or Device • (40h) Write to File or Device

  2. 3Dh Open File • Three File Modes (Stored in AL) • 0 – Input (Read Only) • 1 – Output (Write Only) • 2 – Input/Output • Error Codes (CF=1, AX holds codes) • 1 – Invalid Function Number • 2 – File Not Found • 3 - Path Not Found • 4 – Too Many open files • 5 - Access Denied

  3. Open File .data filename db ‘A:\FILE1.DOC’,0 infilehandle dw ? .code mov ah, 3Dh ;function: open file mov al,0 ;choose the input mode mov dx, offset filename int 21h ;call DOS jc display_error ;error? Display a message mov infilehandle, ax ;no error: save the handle

  4. (3Eh) Close File • Only possible error code • 6 – Invalid handle .data filename db ‘A:\FILE1.DOC’,0 infilehandle dw ? .code mov ah, 3Eh ;function: close file handle mov bx, infilehandle int 21h ;call DOS jc display_error ;error? Display a message

  5. Close File .data filename db ‘A:\FILE1.DOC’,0 infilehandle dw ? .code mov ah, 3Eh ;function: close file handle mov bx, infilehandle int 21h ;call DOS jc display_error ;error? Display a message

  6. (3Fh) Read From File or Device • Can read from keyboard or disk file • First use 3D to open file, then use 3F to read • Errors (CF=1) • 5 – Access Denied • 6 – invalid handle • If CF=0, AX contains # of bytes read • Useful for echecking for EOF

  7. Read from File .data bufferSize = 512 filehandle dw ? buffer db bufferSize dup(0) .code mov ah, 3Fh ;read from file or device mov bx, filehandle ;BX = file handle mov cx, buffersize ;number of bytes to read mov dx, offset buffer ;point to buffer int 21h ;read the data jc display_error ;error if CX=1 cmp ax, cx ;cmp to bytes requested jbe Exit ;yes? Quit reading

  8. (42h) Move File Pointer • AL = Method • 0 – Offset from beginning of file • 1 – Offset from current location • 2 – Offset from end of file • CX:DX holds offset • BX holds filehandle • Errors (CF=1) • 1 – invalid function number • 6 – Invalid Handle • After sucessful operation, CF=0, DS:AX= location of file pointer offset from beginning of file

  9. Move File Pointer/Collect Data .code mov ah, 42h ;function: move pointer mov al,1 ;method: mov bx, filehandle ;BX = file handle mov cx, 0 mov dx, -10 ;offset can be negative int 21h jc display_error ;error if CX=1 mov 3Fh ;function: read file mov cx, 10 ;read 10 bytes mov dx, inbuf int 21h

More Related