| | |
File cursor and the read function
Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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.
I want the cursor to be on the 8'th position, i.e.
Can anyone tell me how can i move it?
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)
TITLE ep1 .MODEL SMALL .STACK 10h .DATA text DB '1234567Start:7890.end',13,10 text_length equ $-text dir db 'D:\myfile.dat',00h buff db 17 dup('$') f_handle dw 1 dup(?) .CODE begin: mov ax,@DATA mov ds,ax ;Create file mov ax,3c00h mov dx,OFFSET dir mov cx,20h int 21h mov [f_handle],ax ;Open file mov ah,3dh mov al, 2 mov dx,OFFSET dir int 21h ;Write file mov ax,4000h mov bx,[f_handle] mov cx,text_length mov dx,OFFSET text int 21h ;Read file mov ax,3f00h mov bx,[f_handle] mov cx,17 mov dx,offset buff int 21h mov ax,4c00h int 21h END begin
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.
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.
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:
A signed offset of +7 is used to access the 8th
byte, because file position start at zero.
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)
mov ah, 0x42 mov bx, [fhandle] sub cx, cx mov dx, 0x7 ; CX:DX=+7 mov al, 0x0 ; from beginning int 0x21
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/
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/
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.
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/
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/
![]() |
Similar Threads
- Fussy Read function & a confused noob :P (C++)
- Read function from text file (C++)
- newbie: read function question (C++)
- Move file pointer to read next file value (C++)
- Pass XML File as Parameter to SP and read it (Oracle)
- Copy file with output read only (Visual Basic 4 / 5 / 6)
- Reading an input file as a class memeber function (C++)
- reading a file into code (Java)
Other Threads in the Assembly Forum
- Previous Thread: exercise help
- Next Thread: Loop Conversion
Views: 911 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for cursor, file, read
.htaccess .net append applicatio array arrays assembly association associations binary bits black bmp c# c++ calling change chmod chooser code comma compress compression console csv cursor data database definedlines delete deserialized directory display download edit error file file-dialog filechooser fstream ftp functions handling header htaccess ifstream image input java javascript kernel line lines linux list loop match mouse mp4 mysql number ofstream open output parameter passing permissions php pointer position print process program properties python read reading remote saving screen search sequential sql store stream string text text-file textarea update upload url validate values variable view web windows write xlib






