Problem with DATA segment labels 
Author Message
 Problem with DATA segment labels

Ok ...

I use tlink :4.01
         tasm: 2.51

example:
.model small

DATEN segment
  {*filter*}db "Here is my label"
DATEN ends

CODE Segment
 Assume CS:Code,DS:DATEN

 lea dx, {*filter*}   ; or mov dx, offset {*filter*}

; Now dx should contain the offset of Crap... Not true I have an
; offset but the one I get in dx isn't high
; dx+180h would be the right offset

Code ends
end

Why do I get these error???

Thanks a lot



Tue, 20 Apr 1999 03:00:00 GMT  
 Problem with DATA segment labels

Quote:

> Ok ...

> I use tlink :4.01
>          tasm: 2.51

> example:
> .model small

> DATEN segment
>   {*filter*}db "Here is my label"
> DATEN ends

> CODE Segment
>  Assume CS:Code,DS:DATEN

>  lea dx, {*filter*}   ; or mov dx, offset {*filter*}

> ; Now dx should contain the offset of Crap... Not true I have an
> ; offset but the one I get in dx isn't high
> ; dx+180h would be the right offset

> Code ends
> end

> Why do I get these error???

The assume command is a directive. That is, a command to the assembler.
DS isn't pointing at your data segment.

What you have to do is to move the address of the data segment into DS.

It should work if you put this in the begining of the code segment:

        mov AX, DATEN   ; Since you can't load an immediate directly into
                        ; a segment register, therefore you must first
                        ; load it into a general-purpous register.
        mov DS, AX      ; And then into the segment register.

Quote:
> Thanks a lot

You're welcome :)


Wed, 21 Apr 1999 03:00:00 GMT  
 Problem with DATA segment labels

Quote:

> .model small

   ^    You use the model directive but do not take advantage of it by
        using simplified segment directives.

Quote:
> DATEN segment

  .const
        Use the .const directive.  Strings that do not change by
        convention are declared in the const segment which is part
        of DGROUP which allows all variables, initialized and
        uninitialized, constant strings and values, and the stack
        to be addressed as from the same segment value, DGROUP.  
Quote:
>   {*filter*}db "Here is my label"
> DATEN ends

        Using the simplified directives, you do not need this segment
        ending directive.  Any segment is terminated when a new segment
        is declared using simplified directives.

Quote:
> CODE Segment

  .code
        Use the simplified code directive as shown.

Quote:
>  Assume CS:Code,DS:DATEN

   ^    When using the .model directive, an assume that is consistent
        with the memory model is defined automatically.  In this case
        Assume cs:_TEXT, ds:DGROUP, ss:DGROUP

        You told the assembler that DS had the segment value of DATEN
        in it, but you did not load that value into DS.  DS is loaded
        with the segment value of the PSP by DOS.  Looking the
        .startup directive which will load the DS register and sets
        SS = DS.  While unintentional, you lied to the assembler and
        that is why the assembler generated incorrect code.  I bet the
        assembler did generate code consistent with what you told it
        to generate.

Quote:
>  lea dx, {*filter*}   ; or mov dx, offset {*filter*}

> ; Now dx should contain the offset of Crap... Not true I have an
> ; offset but the one I get in dx isn't high
> ; dx+180h would be the right offset

        No, you will find that if DS is initialized properly to DGROUP,
        you will get the same offset.  You do not want to address
        variables as offsets from the PSP because in large programs,
        the code may exceed 64K that will mean that you will not be
        able to address any data as an offset from DS register.  The
        DS register must be set to the segment value of the segment
        in which the data resides.

Quote:
> Code ends
> end

Patric,

I hope that this explanation helps.  Most of your problems extend from
the fact that you need to do some more reading of the assemblers
documentation on writing assembly language programs before jumping in.
The TASM documentation, I am sure, comes with a "Hello, World" program
which is what you actually tried to write above.  If the documentation
is not clear you may want to look into some tutorials, see subject #24
in the General Part II of this newsgroup's FAQ.  Some tutorials are
downloadable text files and some are on-line html documents.  Three are
produced from universities around the world and are excellent.  You may
also want to look at subject #19 which reviews some assembly books and
has URLs to more extensive listing available on the internet.  Lastly,
there is much good information for starting assembly language
programmers in the FAQ.

I upload the FAQ to alt.lang.asm, comp.lang.x86.asm, news.answers,
comp.answers, and alt.answers on or about the 21st of every month.
From that posting, the FAQ is archived at rtfm.mit.edu under the two
lang newsgroups.  You can download the FAQ via anonymous ftp.  Also,
I zip the FAQ and upload it to SimTel in the msdos/info directory.
The filename of the latest is asm9610t.zip for the text version and
asm9610h.zip for the html version.  Lastly, the FAQ is available for
viewing and downloading from my web site.  See my .sig below.

Hope that this helps.

Ray
=====================================================================
Ray Moon

http://www.*-*-*.com/ ~raymoon/moonware.html
Home of MoonWare Shareware and the x86 Assembly Language FAQ
Come steal my pages...   Well, not steal but come and see!



Thu, 22 Apr 1999 03:00:00 GMT  
 Problem with DATA segment labels


Quote:
>Ok ...
>I use tlink :4.01
>         tasm: 2.51
>example:
>.model small
>DATEN segment
>  {*filter*}db "Here is my label"
>DATEN ends
>CODE Segment
> Assume CS:Code,DS:DATEN
> lea dx, {*filter*}   ; or mov dx, offset {*filter*}
>; Now dx should contain the offset of Crap... Not true I have an
>; offset but the one I get in dx isn't high
>; dx+180h would be the right offset
>Code ends
>end
>Why do I get these error???
>Thanks a lot

  If you type in this code *exactly* as you have done here then you should
get 0 in dx, which is the correct offset of the variable crap...  But to
get to it you must load ds with the paragraph number of the data segment.
ie:-

        mov     ax,DATEN
        mov     ds,ax

  At the start of your code, before accessing any variables.  When your
program is entered ds contains the paragraph of your Program Segment Prefix
(PSP), and there is probably something between this and the start of your
data segment (Maybe the code segment or a small 80h byte stack, depending
on the segment ordering - I don't know what TASM 2 defaults to...), hence
why adding 180h to dx will allow you to access the variable.

  Umm, sorry if you knew this already and you only included *some* of your
code, but from the code you included that seems to be the problem...

/----------------------------------------------------------------------\
[Hitman/Code HQ - 6502/68000/80386 & now 65816 (16 bit 6502!)          ]
[Assembly Lover since 1987!  A bit of C, but don't tell anyone... :-)  ]
[OS coding/Hardware hitting/Demos/Games/Modules - c64, Amiga & PC      ]
[I'm a pogrammar.. I'm a programor... I'm a progemmar... I write code. ]
\----------------------------------------------------------------------/



Fri, 23 Apr 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problems with Data segment labels

2. data segment vs code segment

3. Help! Data Segment problems

4. Problem to defines DS (data segment)

5. Problems Profiling Code in Data Segment

6. Another problem with the 64K boundary on data segments

7. Program end segment label

8. pmode prob setting up 4G data segment...

9. "data segment" in bootable program

10. "data segment" missing

11. DS and data segment question.

12. get the address of a data segment

 

 
Powered by phpBB® Forum Software