delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/20/05:31:23

From: Vik Heyndrickx <Vik DOT Heyndrickx AT rug DOT ac DOT be>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: segment overrides
Date: Mon, 20 Apr 1998 10:36:23 +0200
Organization: University of Ghent, Belgium
Lines: 40
Message-ID: <353B0906.244E@rug.ac.be>
References: <27B5A316D6D AT fharga DOT sun DOT ac DOT za>
NNTP-Posting-Host: eduserv1.rug.ac.be
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

MNR. LE SMITH wrote:
> 
> hi
> 
> could someone please give me a painfully detailed explanation of
> segment overrides...

This is more a question for comp.lang.asm.x86... 

However, pfff...

For every memory access the CPU references an offset value against a
segment value. Those segment selectors are loaded into one of six
possible segment registers: %es, %cs, %ss, %ds, %fs, %gs. By default
every EXPLICIT memory reference that does not use %esp or %ebp as base
register in a memory reference uses %ds. The one I just excluded for %ds
use %ss by default. Some instructions refer to memory implicitely, like
pushl, popl or stosl (there are more). Those instruction have the
segment register to be used hardwired and therefore you cannot override
that.
For the instructions where it is possible to override the segment
register you specify the bytes 0x26,0x2E,0x36,0x3E,0x64 or 0x65 for the
six segment register I mention above (in the same order).

In DJGPP programs, %ds and %es are both set to the same value and you
would better not change them unless you know very well what you are
doing. The same applies to %cs and %ss. An application program can more
or less safely use %fs and %gs without restoring their value, but
usually few application programs ever need to modify these segment
registers at all.
If you just need to peek from or poke a few bytes into memory you
normally cannot access from a djgpp program it is better relying on
using the _farpeek[bwl] and _farpoke[bwl]. For further information see
the libc reference and the FAQ.


-- 
 \ Vik /-_-_-_-_-_-_/   
  \___/ Heyndrickx /          
   \ /-_-_-_-_-_-_/

- Raw text -


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