Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using segment override

695 views
Skip to first unread message

David G. McDivitt

unread,
Mar 29, 1997, 3:00:00 AM3/29/97
to

To develop an application, I chose assembler, and am really getting to enjoy it.
I never had really gotten serious with assembler and would just get by. Years
ago on mainframes I did a lot of system stuff, but that was different, and the
PC environment offers a whole new scope.

Could someone briefly say what the default segment registers are for the base
and index registers, and when segment override is necessary? I assume using
overrides increases the code size. Since I've been unsure, I put the segment
register on everything, and would like to go through and delete all that.

--
http://cust.iamerica.net/mcdivitt/

William Zandvliet

unread,
Mar 29, 1997, 3:00:00 AM3/29/97
to

I think this is what you need:


Register Default segment register
-------- ------------------------
AX,CX,DX illegal for indexing
BX,SI DS
DI ES
BP SS
SP SS
IP CS

William Zandvliet

David G. McDivitt

unread,
Mar 29, 1997, 3:00:00 AM3/29/97
to

>I think this is what you need:
>
>
>Register Default segment register
>-------- ------------------------
>AX,CX,DX illegal for indexing
>BX,SI DS
>DI ES
>BP SS
>SP SS
>IP CS
>
>William Zandvliet


Yes, that's what I need. Thank you. Is this automatic? Does the assembler do
anything secret based on the PROC/ENDP the code resides within? I wouldn't think
so, but I'm just curious. How many extra bytes or machine cycles or used with
segment overrides?

--
http://cust.iamerica.net/mcdivitt/

William Zandvliet

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

David G. McDivitt wrote:
>
> To develop an application, I chose assembler, and am really getting to enjoy it.
> I never had really gotten serious with assembler and would just get by. Years
> ago on mainframes I did a lot of system stuff, but that was different, and the
> PC environment offers a whole new scope.
>
> Could someone briefly say what the default segment registers are for the base
> and index registers, and when segment override is necessary? I assume using
> overrides increases the code size. Since I've been unsure, I put the segment
> register on everything, and would like to go through and delete all that.
>
> --
> http://cust.iamerica.net/mcdivitt/


My previous reply was incomplete and
contained a mistake. It leaves room for
misunderstanding. I would like to offer
my sincere apologies and a better explanation:


Only BX,SI,DI, and BP can be used as INDEX.
The default segment BX,SI, and DI point at is DS.
The default segment BP points at is SS

e.g. MOV AX,[BX] fills AX with the value at DS:BX
MOV DX,[BP] fills DX with the value at SS:BP


The default segment register for DI is ES
when using STOS, SCAS, and CMPS

e.g. STOSW stores AX at ES:DI


The default segment register for SI is DS
when using LODS and CMPS

e.g. LODSW loads AX with the value at DS:SI
e.g. CMPSW compares the word at DS:SI with
the word at ES:DI


SP points to the location in SS (stack segment)
where the next value is POPped from. If a value
is POPped, SP increases. If a value is PUSHed,
SP decreases.


IP (instruction pointer) points to the location
of the next instruction in CS.

David G. McDivitt

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

>My previous reply was incomplete and
>contained a mistake. It leaves room for
>misunderstanding. I would like to offer
>my sincere apologies and a better explanation:

I forgot one thing to ask. What is the default segment register for memory
addressing, such as

mov ax,bufhead

It's probably DS. That's where I use most of the segment overrides. I put CS: in
front of everything since it's all in the same segment. Surely I could figure it
out through trial and error, but I haven't taken the time to do that yet.

Thanks

--
http://cust.iamerica.net/mcdivitt/

Feico Nater

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

On Sat, 29 Mar 1997 08:15:06 GMT, mcdi...@iamerica.net (David G.
McDivitt) wrote:

>Could someone briefly say what the default segment registers are for the base
>and index registers, and when segment override is necessary?

Code uses always CS, cannot be overridden.
Stack instructions (PUSH, POP, CALL, RET) uses SS. I don't know
whether this can be overridden, but you shouldn't want to.
References using BP or EBP use SS, this can be overridden: They are:
[BP] [SI+BP] [DI+BP] [EBP+d]
[BP+d] [SI+BP+d] [DI+BP+d]
Instructions with implicit use of [DI] or {EDI} use ES. This cannot be
overridden. They are:
STOS SCAS INS
Instructions with implicit use of [DI] or [EDI] and [SI] or [ESI] use
ES with the destination and DS with the source. The latter can be
overridden, the former cannot. They are:
CMPS MOVS
All other instructions use DS. This can be overridden.

>overrides increases the code size.

Yes, it does, although a smart assembler might see that the prefix is
redundant, and delete it.

-----------
Taal Effect
Gerda en Feico Nater
Beukweg 24, 7556 DE Hengelo
tel 074 2506673
fax 074 2506675

Osmo Ronkanen

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

In article <333ccdc1...@news.iamerica.net>,

David G. McDivitt <mcdi...@iamerica.net> wrote:
>To develop an application, I chose assembler, and am really getting to enjoy it.
>I never had really gotten serious with assembler and would just get by. Years
>ago on mainframes I did a lot of system stuff, but that was different, and the
>PC environment offers a whole new scope.
>
>Could someone briefly say what the default segment registers are for the base
>and index registers, and when segment override is necessary? I assume using
>overrides increases the code size. Since I've been unsure, I put the segment
>register on everything, and would like to go through and delete all that.

In normal instructions the default segment is SS if BP is used in
indexing. Otherwise it is DS. In string instructions ES is used with
SCAS, STOS and as destination for MOVS and CMPS. One cannot change that with
any override. DS is used with LODS and for source with MOVS and CMPS.
FS and GS (386+) do not have any default uses.

Yes, a segment override increases the instruction by one byte. But with
then you might avoid the need to constantly change and restore DS. Also
keeping DS to point at the date segment as much as possible is a good way
to avoid bugs.

Osmo


George C. Lindauer

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

William Zandvliet (william....@pi.net) wrote:

: David G. McDivitt wrote:
: >
: > To develop an application, I chose assembler, and am really getting to enjoy it.
: > I never had really gotten serious with assembler and would just get by. Years
: > ago on mainframes I did a lot of system stuff, but that was different, and the
: > PC environment offers a whole new scope.
: >
: > Could someone briefly say what the default segment registers are for the base
: > and index registers, and when segment override is necessary? I assume using
: > overrides increases the code size. Since I've been unsure, I put the segment
: > register on everything, and would like to go through and delete all that.
: >
: > --
: > http://cust.iamerica.net/mcdivitt/
:
: I think this is what you need:

:
:
: Register Default segment register
: -------- ------------------------
: AX,CX,DX illegal for indexing
: BX,SI DS
: DI ES
: BP SS
: SP SS
: IP CS

NONONONONO! DI defaults to DS... the only time it defaults to ES is when
one of the relevant string instructions is used. ALSO sp is not a general
purpose index register... although if you use 32-bit addressing modes
EAX,ECX,EDX,ESP all become general-purpose index registers.
Likewise IP is not a general-purpose index register either... in fact
you can never get at it directly, it only shows up in stack frames. BTW
a neat trick is:

call myfunc
db mydata

proc myfunc
pop esi
do something with data
push esi
ret

I used to use it all the time but it makes debugging hell! Early versions
of turbo pascal really used it a lot...


Note that by use of the ASSUME keyword you can get the assembler to
automatically do the work of figuring out what segment overrides
are needed.

:
: William Zandvliet

David G. McDivitt

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

I sent this once before but it didn't come back across.
----------------------------------

Kate Mohr

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

Combining four responses to reduce spam factor.

David G. McDivitt wrote:
>> a question about over-rides>


>William Zandvliet <william....@pi.net> responded


>I think this is what you need:
>Register Default segment register
>-------- ------------------------
>AX,CX,DX illegal for indexing

On 86

>BX,SI DS
>DI ES
In Stos,etc. but not in Mov ax,[di] for example.

>BP SS
Except as stated below.

>SP SS
>IP CS

This is genarally true for the 86 but wrong in the greater sense for
it's incompleteness.

Di is default as below by Fieco Nater (DS) in common instruction forms
but default in specialized instructions.

32 bit and SIB encoding allows ax,cx and dx as index registers. It is
also possible to have default DS with a complex 32 bit + SIB when using
BP.

Paul


----------------


Feico Nater wrote:
> References using BP or EBP use SS, this can be overridden: They are:
> [BP] [SI+BP] [DI+BP] [EBP+d]
> [BP+d] [SI+BP+d] [DI+BP+d]

Also 32 bit and SIB options should be included but I hate to type, the
manuals have all the permutations. It is hundred all together. Also note
that BP in combination can have a default DS in some odd cases.

> Instructions with implicit use of [DI] or {EDI} use ES. This cannot be
> overridden. They are:
> STOS SCAS INS
> Instructions with implicit use of [DI] or [EDI] and [SI] or [ESI] use
> ES with the destination and DS with the source. The latter can be
> overridden, the former cannot. They are:
> CMPS MOVS
> All other instructions use DS. This can be overridden.

This is correct.

Additionally the following:
The XLAT instruction also has implied use of the DS register with Bx and
can also be over-ridden.

Paul

---------
>(David G. McDivitt) added


>I forgot one thing to ask. What is the default segment register for
>memory addressing, such as
> mov ax,bufhead

An instruction of the form Mov reg,[offset] is DS.

Paul

Osmo Ronkanen

unread,
Mar 30, 1997, 3:00:00 AM3/30/97
to

In article <333d8c9...@news.iamerica.net>,

David G. McDivitt <mcdi...@iamerica.net> wrote:
>>I think this is what you need:
>>
>>
>>Register Default segment register
>>-------- ------------------------
>>AX,CX,DX illegal for indexing
>>BX,SI DS
>>DI ES
>>BP SS
>>SP SS
>>IP CS
>>
>>William Zandvliet
>
>
>Yes, that's what I need. Thank you. Is this automatic? Does the assembler do
>anything secret based on the PROC/ENDP the code resides within?

It is a feature of the processor. The assembler has nothing to do with
it. The assembler on the other hand can generate overrides on basis of
what you have told it on the segment registers. That means for example
that if you have ASSUME CS:CODE,DS:DATA and the have a variable in the
code segment then the assembler automatically generates an override for it.
IT is a good thing to change the assumptions when you change segment
registers (most typically DS). In that way the assembler can detect
errors for you.

>I wouldn't think
>so, but I'm just curious. How many extra bytes or machine cycles or used with
>segment overrides?
>

That depends on the CPU. I think it is one on 386 and that or less on
newer ones. In general it is not something gone should terribly worry. A
good thing is just to use DS for data segment and ES, FS, GS for others.

Osmo


Osmo Ronkanen

unread,
Mar 31, 1997, 3:00:00 AM3/31/97
to

In article <333DA1...@pi.net>,

William Zandvliet <william....@pi.net> wrote:
>
>Only BX,SI,DI, and BP can be used as INDEX.

That is incorrect. Only SI or DI can be used as index and only BX or BP
can be used as base. One can use [base+index+displacement] or any subset
of it. That means [BP+BX] and [SI+DI] are illegal.

>The default segment BX,SI, and DI point at is DS.
>The default segment BP points at is SS
>
> e.g. MOV AX,[BX] fills AX with the value at DS:BX
> MOV DX,[BP] fills DX with the value at SS:BP
>

Actually SS is used if the base is BP. Otherwise DS is used.

Osmo


Osmo Ronkanen

unread,
Mar 31, 1997, 3:00:00 AM3/31/97
to

In article <333dcc1...@news.iamerica.net>,

David G. McDivitt <mcdi...@iamerica.net> wrote:
>>My previous reply was incomplete and
>>contained a mistake. It leaves room for
>>misunderstanding. I would like to offer
>>my sincere apologies and a better explanation:
>
>I forgot one thing to ask. What is the default segment register for memory
>addressing, such as
>
> mov ax,bufhead
>
>It's probably DS. That's where I use most of the segment overrides.

Default at what level? On machine code level the default is DS. On
assembler level it depends on what segment the variable is in. If it can be
accessed with DS then DS is used (that is no override). Otherwise proper
override is created or an error message is generated.

>I put CS: in
>front of everything since it's all in the same segment.

Why? Why not just make sure that DS points to the same segment. Remember
that using overrides is the exception. Also if you handle assumptions
correctly you do not have to worry about overrides in cases like this
(that is labels instead of numeric offsets.)

> Surely I could
>figure it out through trial and error, but I haven't taken the time to
>do that yet.
>
>Thanks
>
>--
>http://cust.iamerica.net/mcdivitt/


Osmo

Scott Nudds

unread,
Apr 1, 1997, 3:00:00 AM4/1/97
to

William Zandvliet <william....@pi.net> wrote:

: Register Default segment register


: -------- ------------------------
: AX,CX,DX illegal for indexing
: BX,SI DS
: DI ES
: BP SS
: SP SS
: IP CS


ES is only the base segment when it is used in string operations.
Otherwise it is DS.

Segment overrides are needed when ever the default segments (above)
need to be altered.

Is there ever a CS:IP override? Not even sure what that would mean.

--
<---->


Dan Ramage

unread,
Apr 1, 1997, 3:00:00 AM4/1/97
to

Scott Nudds wrote:
> Is there ever a CS:IP override? Not even sure what that would mean.

It would mean that you access info in the code set at whatever offset
the top of the stack is at. What else would it mean?


Dan Ramage
http://www.geocities.com/SiliconValley/9577/


Maitre d'

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

> Could someone briefly say what the default segment registers are for the
base
> and index registers

DS for all everything except and string destination (ES), and
stack access (SS), and anything using ESP, or (E)BP. Example:
mov ax, [1234] ;DS
lods ;DS
cmp [bx+si], di ;DS

string destination:
stos ;ES
cmps ;ES
movs ;ES
scas ;ES

stack access:
mov ax, [bp + 12] ;SS
cmp [bp + si], ax ;SS
mov [esp + 1234], 1 ;SS

>and when segment override is necessary?

Whenever the default segment is not the segment to which you
want to refer (note that you can't override string
destination - it's always ES).
example: change default from DS to CS, for move:
mov ax, cs:[1234]

>I assume using overrides increases the code size.

One byte per override.

> Since I've been unsure, I put the segment register on
>everything

A good assembler will realise when your override matches the
default, and remove it during assembly.

William Zandvliet

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

Osmo:

You are absolutely right. What I meant was that only
BX,SI,DI, and BP can be used as a MEMORY POINTER.
I used the wrong term.

Another thing I stated that is not entirely correct
was this:

The default segment register for DI is ES

when using string instructions (STOS, SCAS, CMPS, MOVS)

It should have been:

The segment register for DI when using string
instructions is ALWAYS ES. It can NOT be overridden.

William

Michael Tippach

unread,
Apr 2, 1997, 3:00:00 AM4/2/97
to

Maitre d' wrote:

> DS for all everything except and string destination (ES), and
> stack access (SS), and anything using ESP, or (E)BP. Example:

[... snipp ...]

EBP used as an index register defaults to DS, not to SS as one
might think.

Regards
Wuschel

Scott Nudds

unread,
Apr 4, 1997, 3:00:00 AM4/4/97
to

: Scott Nudds wrote:
: > Is there ever a CS:IP override? Not even sure what that would mean.

Dan Ramage (dra...@worldnet.att.net) wrote:
: It would mean that you access info in the code set at whatever offset


: the top of the stack is at. What else would it mean?

What has the stack to do with this?

The confusion comes from the possible use of overrides to perform
intersegmeng jumps/calls, or their use to "possibly" override jumps/calls
from tables held in alternate segments.

0 new messages