File cursor and the read function

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jun 2008
Posts: 105
Reputation: Alex_ is an unknown quantity at this point 
Solved Threads: 2
Alex_'s Avatar
Alex_ Alex_ is offline Offline
Junior Poster

File cursor and the read function

 
-1
  #1
Sep 25th, 2009
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.
  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?
Fundamental law of life:
do{ ThingsToDo+=me.CompleteTask(ThingsToDo); }while(ThingsToDo); Die(me);
Law of the Spirit:
do{ Rebuke(me); }while(!me.Repented); LiveEternal(me);
PM me to know more why i wrote this or what it means.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 143
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster

Re: File cursor and the read function

 
1
  #2
Sep 25th, 2009
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:
  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.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 143
Reputation: NotNull is an unknown quantity at this point 
Solved Threads: 14
NotNull's Avatar
NotNull NotNull is offline Offline
Junior Poster

Re: File cursor and the read function

 
0
  #3
Sep 25th, 2009
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.
----------------------------------------------------------
To control a mind violates a man, and all it has been used for is
hurting and afflicting. Nowonder I progam in assembly...
--->Now available http://dotcoding.netai.net/
Reply With Quote Quick reply to this message  
Reply

Tags
cursor, file, read

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 915 | Replies: 2
Thread Tools Search this Thread



Tag cloud for cursor, file, read
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC