Re: referring to segments other than DS - how?



On Wed, 27 Feb 2008 11:04:31 -0800, japheth wrote:

in 16bit, if you're using the .model directive (ie .model small), @data
will be the "group" of the data segment. Then both logical segments
_DATA and _BSS are contained in the same physical segment (which is
called DGROUP) and the "offset" operator will refer to the physical
segment then (at least with MASM v6+).

I think this is more clear to me now. Feel free to correct me if I'm
wrong.

In looking at the opcodes for:

mov ax, _bss

it is something like:

B8 BD 13 ==> intel ==> mov ax, 13BD

And if I have already declared in a label in BSS (masm's ".data?"
directive) like this:

..data?
MyFileHandle WORD ?

and then if I later copy ax to that memory location labeled MyFileHandle,
the opcode will look something like this:

A3 84 03 ==> intel ==> mov word ptr [384], ax

My first expectation was that this would be "mov word ptr [0], ax",
because I was thinking that there was a separate physical section, and
"MyFileHandle" would reference the 1st byte in that section. This is
wrong!

The processor doesn't really know about the bss section - the processor
just moves the value in ax into the memory location which is 384 (hex)
bytes into the physical data segment (DGROUP). This location (384h) can
be in multiple logical segments. If the physical data segment starts at
segment 13A4 then the following reference refers to that same location

==> 13A4:0384,

and this is 13DC4h bytes from the beginning of the program's memory
(13A40h + 384h). Each segment is 16 bytes from the last segment.
Segment 0001 is 16 bytes higher than segment 0000.

THIS segment/offset, 13BD:01F4

also refers to the same physical location as 13A4:0384.

==> 13BD0h + 01F4h = 13DC4h, and
==> 13A40h + 0384h = 13DC4

Again, each segment is a logical 16 (decimal) byte block. So, segment
0001 is at byte 16d in the program's memory. We can multiply the segment
by 16d (or, 10h) to find the exact location in the program of that
segment. Segment 0002 * 10h = 00020h bytes into the memory.


If BSS is at logical segment 13BD, and DS is at logical segment 13A4,
then BSS is 19h segments higher than DS, or 190h bytes higher than DS
(400 decimal bytes).

13BDh - 13A4h = 19h

19 segments is 19h * 10h bytes. 190h bytes.

Hopefully, I'm right about this. If so, maybe this will help another
newbie reading the forum. Feel free to correct or add.

--
Regards,
Pop Tart
.



Relevant Pages

  • Re: C and ELF segment
    ... it mentions that BSS segment only stores the ... language does not actually specify things like segments, a BSS ... int main{ ...
    (comp.lang.c)
  • Re: Is it Data Segment ?
    ... are allocated in the data segment. ... Some aggressive compilers place .data into .bss instead, ... You mean like when you upload from an EPROM into a prom ... edit the initialization values in the data ...
    (comp.os.linux.development.system)
  • Re: referring to segments other than DS - how?
    ... With int 21h function 3Fh, I'm trying to write then read an array of ... I know how to set DS to "DATA" segment in MASM: ... mov ax, @data ... so for BSS, would it be: ...
    (alt.lang.asm)
  • Re: static char overflow
    ... > exotic compiler, the .dtors section is after the bss. ... section is always put at the end of the data segment (the 2nd PT_LOAD ... This has to be the case, since .dtors is always initialized. ...
    (Vuln-Dev)
  • Re: [patches] [PATCH] [18/19] x86_64: Overlapping program headers in physical addr space fix
    ... It maps smp alternatives sections which will ... It also maps .bss, which will never ... Then create a segment 'init' for all the init ...
    (Linux-Kernel)