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.

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

I want the cursor to be on the 8'th position, i.e.
Can anyone tell me how can i move it?

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:

mov ah, 0x42
mov bx, [fhandle]
sub cx, cx
mov dx, 0x7 ; CX:DX=+7
mov al, 0x0  ; from beginning
int 0x21

A signed offset of +7 is used to access the 8th
byte, because file position start at zero.

commented: Thanks. Just what i needed. +2

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.