×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Invalid string offset AH=9 INT21h

Invalid string offset AH=9 INT21h

Invalid string offset AH=9 INT21h

(OP)
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

RE: Invalid string offset AH=9 INT21h

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!"

RE: Invalid string offset AH=9 INT21h

(OP)
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.

RE: Invalid string offset AH=9 INT21h

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

    ...

RE: Invalid string offset AH=9 INT21h

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

RE: Invalid string offset AH=9 INT21h

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!"

RE: Invalid string offset AH=9 INT21h

->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.

RE: Invalid string offset AH=9 INT21h

(OP)
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! :)

RE: Invalid string offset AH=9 INT21h

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..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close