The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: korte on April 22, 2007, 05:40:25 PM

Title: DS=0000
Post by: korte on April 22, 2007, 05:40:25 PM
How to define data segment pointing 0?

My program run DOS, compiling ML.


xdata segment 'DATA'
sampleoff db "HELLO"
xdata ends

code segment

mov esi,offset sampleoff
mov [sampleoff],'A'

Want DS=0 (flat memory and LFB)
now using fs to pointing LFB and XMS but uggly (and slow) segment prefix, want all offset 0 relativ (ds=0000)

but problem defining data segment

(sorry litle english)





Title: Re: DS=0000
Post by: korte on April 23, 2007, 06:00:14 PM
Not understod my question?
Sorry litle english
Title: Re: DS=0000
Post by: dsouza123 on April 23, 2007, 06:29:26 PM
Your initial question seems OK,

Many people posting here only know about Windows 32 bit flat memory,
which doesn't involve changing or switching between the segment registers,
(or at least in the programming I've done), so they wont be able to answer.

You seem to be asking about DOS with XMS (maybe 32 bit esi shown in code snippet)
and switching from the FS to the DS segment.
Title: Re: DS=0000
Post by: MichaelW on April 23, 2007, 06:37:55 PM
korte,

Is your question about the VESA BIOS Extensions and using the Linear Frame Buffer?

Title: Re: DS=0000
Post by: japheth on April 23, 2007, 07:18:43 PM

Or he might want to use UNREAL mode?

Because that's the fastest solution for VESA LFB access if the program runs in true real-mode.

If this is the case, I might suggest to post the question in the FASM forum which is ways better for DOS and/or low-level questions. There is also some example code for UNREAL mode.


Title: Re: DS=0000
Post by: korte on April 24, 2007, 05:41:45 PM
I would like the pointers of the Data Segment to point to physical
addresses when I compile with MASM in DOS enviroment.

For example:

xdata segment 'data'
sampledata label byte
xdata ends

  mov edi, offset sampledata


I would like the edi's value won't be ds:0 but the runtime physical
address according to 0 segment.

It's because the DS register's value is 0 in my program (because of
the XMS and VESA LFB) and I don't want to use another segment
register.

Or is it possible to set the datasegment's position at
compile time?
Title: Re: DS=0000
Post by: MichaelW on April 24, 2007, 10:12:58 PM
If I understand you correctly, you need to make MASM encode the data references in your code so they are relative to segment 0, instead of relative to the load address of your data. To do this I think you need to define an AT segment, define you data in that segment (only uninitialized data is allowed), and then use an ASSUME to tell MASM to associate that segment with segment register DS. MASM should then be able to encode all the data references in your code correctly. Sorry, I don't have time right now to code an example. For information see Using Full Segment Definitions and  Setting the ASSUME Directive for Segment Registers  here (http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_02.htm).
Title: Re: DS=0000
Post by: sinsi on April 25, 2007, 02:43:32 AM
Here's part of some code I have used in the dim dark past

biosdata segment at 40h
org 4ah
screen_columns word ?
biosdata ends
...
    mov ax,biosdata
    mov ds,ax            ;DS=0040
    assume ds:biosdata
    mov ax,screen_columns
...


So in your case you would do

xdata segment at 0
sampledata label byte
xdata ends
  mov ax,xdata ;sub ax,ax
  mov ds,ax
  ASSUME DS:xdata
  ...
  mov edi, offset sampledata


Of course you can override with DS:

xdata segment at 0
sampledata label byte
xdata ends

cseg segment
  mov ax,xdata ;sub ax,ax
  mov ds,ax
  ASSUME DS:xdata
cseg_label word 0
  ...
  mov ax,ds:cseg_label  ;this gets the offset right but used DS instead of CS
cseg ends