DS and data segment question. 
Author Message
 DS and data segment question.

Ok in NASM, I see the line
[ORG 0x0100]

which tells us where the data segment starts right?
if that is the case then why in my code segment do I still have to
do

mov AX, 0100h
mov DS, AX

I thought that is what the ORG does.
Am I missing something?

Thanks



Tue, 22 May 2001 03:00:00 GMT  
 DS and data segment question.

Quote:

> Ok in NASM, I see the line
> [ORG 0x0100]

> which tells us where the data segment starts right?

It tells the assembler where to 'assume' the following chunk
will finally be loaded into memory.

For example, if right afterwards, you have

  a dw 0
  b dw 0

Then the assembler is 'assuming' that when the program is
finally loaded, a will be at 0x0100, and b will be at 0x0102.

So that if you write:

  mov si, b

Assembler would produce

  mov si, 0x0102

Note: It's not necessarily the 'data' segment.
It's what follows your org statement.

Quote:
> if that is the case then why in my code segment do I still have to
> do

> mov AX, 0100h
> mov DS, AX

First of all, the org statement changes the starting 'offset',
it does not change the starting 'segment', since in general,
a .COM/.EXE file may be loaded into anywhere in memory, and so
the assembler and you can not possibly know ahead of time what
segment your program will be loaded into at run time.

Are you sure you are quoting the code correctly?

(Set DS to be 0100h means you will then be accessing
data between 0100h:0h to 0100h:0ffffh,  which is probably not
where your program is loaded (unless you're doing boot sector
or OS development...)

Quote:
> I thought that is what the ORG does.
> Am I missing something?

ORG only changes the assumption of the starting OFFSET.

It does not change the ACTUAL OFFSET
(unless you're producing an EXE file, where your
choice will be recorded into the EXE header)

And it definitely can not do anything about the
starting SEGMENT location.

- Walter



Tue, 22 May 2001 03:00:00 GMT  
 DS and data segment question.
|Ok in NASM, I see the line
|[ORG 0x0100]
|
|which tells us where the data segment starts right?
|if that is the case then why in my code segment do I still have to
|do

ORG just moves the assembler's offset pointer within the current
segment to another location. It's kind of like a JMP instruction
for the assembler.

ORG doesn't tell you what segment your code/data data is in.
You'll have to get that by MOVing the segment to a reg/mem

    mov    ax,DATA    ;Assumes the segment is called DATA
    mov    ds,ax      ;DS points to a segment called DATA

The reason most people use ORG is to create .COM files. .COM files
are loaded by DOS at CS:0100, so the code segment must start at
offset 100h within the first segment used by the program.
The 100h bytes before the code is the PSP.

|
|mov AX, 0100h
|mov DS, AX

MOV AX,SegName
mov ds,ax



Tue, 22 May 2001 03:00:00 GMT  
 DS and data segment question.

Quote:

> Ok in NASM, I see the line
> [ORG 0x0100]

> which tells us where the data segment starts right?

Wrong. This line tells us where the _code_offset_ starts. This is only
for .COM files. COM files only have one segment as you know (CS=DS).
When DOS loads a COM file, the first 256 (0x0100) bytes are reserved for
the PSP (Program Segment Prefix), which is DOS internal data used for
this program. It contains things like command-line arguments. Thus the
code will start at offset 0x0100. In order to do JMPs and CALLs
correctly, NASM must know that its code starts at 0x0100 (ORG = ORiGin).

Quote:
> if that is the case then why in my code segment do I still have to
> do

> mov AX, 0100h
> mov DS, AX

No. DS=CS, Code starts at CS:0x0100. The PSP is from CS:0000 to CS:00FF
(or DS). doing what you wrote up there would be totally wrong.

Jan

--

+-------------------------------------+
| Jan Oberl?nder                      |

| PGP key available on request        |
+-------------------------------------+



Wed, 23 May 2001 03:00:00 GMT  
 DS and data segment question.

Quote:

> code will start at offset 0x0100. In order to do JMPs and CALLs
> correctly, NASM must know that its code starts at 0x0100 (ORG = ORiGin).

  Actually, it doesn't need to know where the code starts
in order to do the usual short or near JMPs or CALLs.
All of those are IP-relative, so the generated code is
correct even if the ORG is wrong.  We have seen lots of
bootstraps and a few COM files posted here that would
fail immediately if the ORG needed to be correct for
near JMPs.

  Many other things in a program might be wrong if the
ORG used by the assembler differs from run-time
starting offset.  It is a good idea to make it
correct;  Just don't cite the JMPs and CALLs as the
reason.
--
http://www.erols.com/johnfine/
http://www.geocities.com/SiliconValley/Peaks/8600/



Thu, 24 May 2001 03:00:00 GMT  
 DS and data segment question.
The init hex of the segment is at a line number.  There are is no DS
starting address. The datasegment is called DataSG and the Codesegment
CodeSG.  When the program batches, it builds object code in form of a source
program not an executable, it still has to be linked before it is
executable. Did that help or just confuse you !
anyway there are 87 assembler instructions from AAA to XOR.


Mon, 28 May 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem to defines DS (data segment)

2. initialize DS to data segment

3. Init 4GB segment limit for ES and DS

4. Loading code segments into DS

5. Loading code segments into DS

6. Stack Segment Vs DS:

7. data segment vs code segment

8. Data Segment Question

9. ds ds

10. moving data into DS

11. moving data into DS

12. mov ds,seg text why not??? newbie question

 

 
Powered by phpBB® Forum Software