Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The offset value

Status
Not open for further replies.

lcontador

Technical User
Jan 20, 2001
2
0
0
BR
I´m tried to open a file to write in it, but in every place that I look for, they say to me that I need enter with the off set value, like in the bellow example .

mov ax,3d02h
mov dx,offset cs:fname ; DX=*FileName
int 21h ; DOS/FileOpen
jc errorlbl ; Jump On Errors

mov word ptr [offset cs:fname],ax ; BX=Handle
mov bx,ax

mov ax,4200h
xor cx,cx ; Segment
mov dx,23ceh ; Offset
int 21h ; DOS/FileSeekSet
jc errorlbl ; Error !

mov ax,4000h
mov bx,word ptr [offset fname] ; BX=Handle
mov cx,6 ; Lenght
mov dx,offset patch ; Buffer
int 21h ; DOS/WriteFile
jc errorlbl

mov ax,3e00h
mov bx,word ptr [offset fname] ; BX=Handle
int 21h ; DOS/CloseFile
jc errorlbl

My answer is : How can i found the offset value of a specifie instruction ?
 
The first that catches my eye is this line:
mov dx,offset cs:fname ; DX=*FileName ????

The first thought that comes to mind is that you are trying to write a COM program where DS = CS in which case this will work much more efficiently:
MOV DX, OFFSET fname;

My second thought is that you declared fname as a variable in the code seg, in which case you need to save DS and then set DS = CS before performing the INT, and then restore DS before returning. But the CS segment overide is still not neccessary for the MOV DX, OFFSET fname.
 
Hi.

Put a label before your opcode (instruction), and get the offset b using - offset label.

Example:
label1:
mov bx,10
mov ax,30
mov dx,offset label1

;At this point, dx will contain the offset of the instruction: mov bx,10 (the first byte).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top