1 / 13

Writing and reading files

Writing and reading files. Creating a file on a disk. Get a file handle from system Use INT 21H function 3C to create a directory entry for the file Use INT 21H function 40H to write records to the file Use INT 21H function 3EH to close the file. Create a file. filename DB 'data.dat',0

wyanet
Download Presentation

Writing and reading files

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. Writing and reading files

  2. Creating a file on a disk • Get a file handle from system • Use INT 21H function 3C to create a directory entry for the file • Use INT 21H function 40H to write records to the file • Use INT 21H function 3EH to close the file

  3. Create a file filename DB 'data.dat',0 handle DW ? prompterror DB 'Error while creating this file ','$'

  4. INT 21H function 3CH mov cx, 0 ; File attribute LEA dx, filename mov ah, 3ch int 21h jc err mov filehandle, ax jmp exit err: MOV AH, 09H LEA DX, prompterror INT 21H

  5. File attribute File attribute defines the type of file. One file may have more than one attribute 00H: normal file 01H: read only file 02H:hidden file 04H: system file (more information, please see page 301)

  6. INT 21H Function 40H MOV Ah, 40H MOV BX, filehandle MOV CX, 256 ; number of bytes to write to disk LEA DX, DISKAREA ; the area to write to disk INT 21H JC error CMP AX, 256 JNE error

  7. INT 21H function 3EH: close file • MOV AH, 3EH • MOV BX, filehandle • INT 21H • JC error

  8. Reading a file • Use INT 21H function 3Dh to open a file • Use INT 21H function 3FH to read records from the file • Use INT 21H function 3EH to close a file

  9. Open a file using INT 21H function 3DH • 000: read only • 001: write only • 010: read/write

  10. Open file for reading MOV AH, 3DH MOV AL, 00H ; Access code = 00 = read only LEA DX, FILENAME INT 21H JC error MOV filehandle, AX Data: filehandle DW ?

  11. INT 21H function 3F – Read record Data: Filehandle DW ? INAREA DB 512 DUP(‘ ‘)

  12. Code MOV AH, 3FH MOV BX, filehandle MOV CX, 512 LEA DX, inarea INT 21H JC error CMP AX, 00 JE exit

  13. Final exam • Date: Tuesday May 9, 10am-12pm • Open book • Format (multiple choices, problem solving, determine the errors from code, 2 programming problems) • Focus: everything from Week 1 to Week 14

More Related