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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid string offset AH=9 INT21h

Status
Not open for further replies.

TheVisitor

IS-IT--Management
Oct 11, 2002
6
US
I can't get the right offset to the string!
When I disassemble my .COM file, the LEA line would read:
MOV DX,0000
Can somebody tell me what I am doing wrong?
------------------- MY CODE
ASSUME CS:CODE_SEG,DS:DATA_SEG

CODE_SEG SEGMENT
ORG 100h
MAIN PROC NEAR

MOV AH,09
LEA DX,USAGE_LINE
INT 21h
INT 20h

MAIN ENDP
CODE_SEG ENDS

DATA_SEG SEGMENT
USAGE_LINE DB 'VID.COM v0.0.0 [:IO:] 2002 ',0Dh,0Ah
DB 0Dh,0Ah
DB 'options: d DISPLAY INFO',0Dh,0Ah
DB ' s SCAN LINES (0..2)',0Dh,0Ah
DB ' v VIDEOMODE (0..255)',0Dh,0Ah
DB ' f FONT HEIGHT (8,14,16)',24h

DATA_SEG ENDS
END MAIN
 
try using the following

mov dx,OFFSET usage_line

to be honest i never understood the use of LEA unless converting effective address from 16 to 32 and visa.

for example if in 16 bit mode and you wanted a 32bit effective address then use the following:

lea edx,OFFSET usage_line
"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
Unfortunatelly your suggestions didn't work:
MOV DX,OFFSET USAGE_LINE and LEA DX,OFFSET USAGE_LINE.

I tried to put an ORG 100h in the DATA_SEG part too,
that did not work either. Disassembled the line would say
MOV DX,0100 though, but the string started at offset 0210h!

I think I'll use a LODSB loop instead.
Thanks.
 
ASSUME CS:CODE_SEG,DS:DATA_SEG

CODE_SEG SEGMENT
ORG 100h
MAIN PROC NEAR

MOV AX,DATA_SEG ; !!!!!!!!!!!!!!!!!!!!
MOV DS,AX ;

MOV AH,09
LEA DX,USAGE_LINE

...
 
ASSUME CS:CODE_SEG,DS:DATA_SEG

CODE_SEG SEGMENT
ORG 100h
MAIN PROC NEAR

; !!!!!!!!!!!!!
MOV AX,DATA_SEG
MOV DS,AX
; !!!!!!!!!!!!!

MOV AH,09
LEA DX,USAGE_LINE
INT 21h
INT 20h

MAIN ENDP
CODE_SEG ENDS

DATA_SEG SEGMENT
USAGE_LINE DB 'VID.COM v0.0.0 [:IO:] 2002 ',0Dh,0Ah
DB 0Dh,0Ah
DB 'options: d DISPLAY INFO',0Dh,0Ah
DB ' s SCAN LINES (0..2)',0Dh,0Ah
DB ' v VIDEOMODE (0..255)',0Dh,0Ah
DB ' f FONT HEIGHT (8,14,16)',24h

DATA_SEG ENDS
END MAIN
 
yes, thats a good one! setting the data segment to the code for com files is a great idea:

push cs
pop ds

i always thought that com files only have one segment so your code and data share the same space, dont create a new segment just put the data after the last endp.

i would still use:

mov dx,OFFSET blah
or
lea dx,OFFSET blah

your assembler might take your label as an indirect immediate and error with operand size conflict.
maybe you could do some testing to see what works best for you?


"People who have nothing to say, say it too loud and have little knowledge. It's the quiet ones you need to worry about!"
 
->straiph
It's good idea to define two segment in listing of
COM program. You would like to do anything but
linker doesn't it.

 
The
MOV AX,DATA_SEG
MOV DS,AX
lines did not work. I could not create a .COM with it.
Linker said: "Segment relocatable items present".
The PUSH CS and POP DS lines resulted in a MOV DX,[0000] line.

I figured out how to do it. GROUP the two segments.
above the ASSUME line it would say, for example:
GROUP CGRP CODE_SEG, DATA_SEG.
(or was it GROUP CGRP CS:CODE_SEG, DS:DATA_SEG?
(I haven't looked at it for some time..))

With this line inserted I got the right offset to the string.

PS.
I think I'd better migrate to MASM 5.00 style! :)
 
both the assembler and the linker were right!
assembler gave 0 offset for your string as it DOES HAVE 0 offset in the DATA segment.
and naturally, the linker was puzzled to meet more than one segment in COM file.
GROUP worked, sure , but you'd better get rid of data segment and put all the stuff in to code segment. finally, that's what a com file is expected to be..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top