www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/14/15:14:05

Newsgroups: comp.os.msdos.djgpp
Date: Fri, 14 Feb 1997 12:45:25 -0700 (MST)
From: Matthew Mastracci <mmastrac AT acs DOT ucalgary DOT ca>
To: Nikita Proskourine <nproskou AT goucher DOT edu>
Cc: djgpp AT delorie DOT com
Subject: Re: data segment in NASM (repost)
In-Reply-To: <Pine.SUN.3.91.970213153105.26238B-100000@rwd>
Message-Id: <Pine.A41.3.94.970214123622.84538A-100000@acs2.acs.ucalgary.ca>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970213153105 DOT 26238B-100000 AT rwd>
Mime-Version: 1.0

On Thu, 13 Feb 1997, Nikita Proskourine wrote:

> 
> What's the proper way of loading DS with the value of my data segment in
> NASM? The docs don't say anything about this (or maybe I am just using an
> old version or didn't read the docs carefully). NASM gives me an error
> when I try to compile the program: something like "Undefined symbol
> '.data'" But it's the name of my data segment! Why can't I use a MOV < >,
> SEG .data instruction?

I wouldn't worry about explicitly loading DS.  DS is always (unless you
mess with it) loaded with the selector referencing your data.  This
includes: all your C variables, your ASM variables and all the malloc()ed
memory you've taken.  If you're talking about modifying DS and then
recovering it: don't forget that NASM doesn't know what the selector of
your data segment will be (it isn't known until runtime)!  If you want to
load/unload it, try: 

Just use: 

[bits 32]

[section .text]

mov [_SaveDS], ds
mov ds, [_NewDS]
; code
mov ds, [_SaveDS]

[section .data]

dw _SaveDS    0000h
dw _NewDS     0000h  ; Fill with your favorite selector somewhere

if you want to access the data segment.  This *should* work, but I'm just
running it off the top of my head.  If you post a small code snippet, we
may be able to help a little more.

/\/\att /\/\astracci                  mmastrac AT acs DOT ucalgary DOT ca

GCS/GE    d- s+:+ a--- C++++ UA P+ L E-- W+ N++ o K+ w+ O M- V 
          PS++ PE++ Y+ PGP t+++ 5+++ X++ R++ tv+ b+++ DI++++ I 
          G++ e h r* z?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019