943,536 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Marked Solved
  • Views: 2074
  • Assembly RSS
Sep 25th, 2009
-1

File cursor and the read function

Expand Post »
Hey guys.
I want to read from a file created by me from a specific position. But i don't know how to move the file cursor.
Assembly Syntax (Toggle Plain Text)
  1. TITLE ep1
  2.  
  3. .MODEL SMALL
  4. .STACK 10h
  5. .DATA
  6. text DB '1234567Start:7890.end',13,10
  7. text_length equ $-text
  8. dir db 'D:\myfile.dat',00h
  9. buff db 17 dup('$')
  10. f_handle dw 1 dup(?)
  11.  
  12. .CODE
  13. begin: mov ax,@DATA
  14. mov ds,ax
  15. ;Create file
  16. mov ax,3c00h
  17. mov dx,OFFSET dir
  18. mov cx,20h
  19. int 21h
  20. mov [f_handle],ax
  21. ;Open file
  22. mov ah,3dh
  23. mov al, 2
  24. mov dx,OFFSET dir
  25. int 21h
  26. ;Write file
  27. mov ax,4000h
  28. mov bx,[f_handle]
  29. mov cx,text_length
  30. mov dx,OFFSET text
  31. int 21h
  32. ;Read file
  33. mov ax,3f00h
  34. mov bx,[f_handle]
  35. mov cx,17
  36. mov dx,offset buff
  37. int 21h
  38.  
  39. mov ax,4c00h
  40. int 21h
  41. END begin
I want the cursor to be on the 8'th position, i.e.
Can anyone tell me how can i move it?
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster
Alex_ is offline Offline
175 posts
since Jun 2008
Sep 25th, 2009
1

Re: File cursor and the read function

INT 21 - DOS 2+ - "LSEEK" - SET CURRENT FILE POSITION
AH=42h
AL=origin of move
00h - start of file
01h - current file position
02h - end of file
BX=file handle
CX : DX = (signed) offset from origin of new file position
return: CF clear if successful
DX:AX =new file position in bytes from start of file
CF set on error
AX=error code

To get to the 8th byte of the file:
Assembly Syntax (Toggle Plain Text)
  1. mov ah, 0x42
  2. mov bx, [fhandle]
  3. sub cx, cx
  4. mov dx, 0x7 ; CX:DX=+7
  5. mov al, 0x0 ; from beginning
  6. int 0x21
A signed offset of +7 is used to access the 8th
byte, because file position start at zero.
Last edited by NotNull; Sep 25th, 2009 at 3:51 pm.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008
Sep 25th, 2009
0

Re: File cursor and the read function

Why do you open the file with 3Dh when you already
have the file handle returned by 3Ch?
This will create two file handles that refer to the same
file, so if you want to be a well-behaved application
and close your open files you'll have to close both.
But most MS-DOS versions close all open files upon termination.
Also note that when you open the same file twice to get
two file handles, they will share the same file pointer position.
Reputation Points: 36
Solved Threads: 19
Junior Poster
NotNull is offline Offline
198 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: exercise help
Next Thread in Assembly Forum Timeline: Loop Conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC