Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Access to data, BSS segments will be through using a pointer or byintructions directly addressing ?

Reply
Thread Tools

Access to data, BSS segments will be through using a pointer or byintructions directly addressing ?

 
 
Good Guy
Guest
Posts: n/a
 
      10-18-2010
I know when it's a matter of accessing memory of a stack frame it'll
be through using stack frame pointer but I wonder about how the access
to data, BSS segments containing global/static data will be, through
using a pointer like stack frame pointer indicating starting point of
those segments or instructions address pieces of those segments
directly so that each time application starts the system will have to
write address parts of instructions in text segment ?
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      10-18-2010
On Oct 18, 1:11*pm, Good Guy <(E-Mail Removed)> wrote:
> I know when it's a matter of accessing memory of a stack frame it'll
> be through using stack frame pointer but I wonder about how the access
> to data, BSS segments containing global/static data will be, through
> using a pointer like stack frame pointer indicating starting point of
> those segments or instructions address pieces of those segments
> directly so that each time application starts the system will have to
> write address parts of instructions in text segment ?


Depends on your implementation.

 
Reply With Quote
 
 
 
 
Amarpreet Singh
Guest
Posts: n/a
 
      10-19-2010
On Oct 19, 1:11*am, Good Guy <(E-Mail Removed)> wrote:
> I know when it's a matter of accessing memory of a stack frame it'll
> be through using stack frame pointer but I wonder about how the access
> to data, BSS segments containing global/static data will be, through
> using a pointer like stack frame pointer indicating starting point of
> those segments or instructions address pieces of those segments
> directly so that each time application starts the system will have to
> write address parts of instructions in text segment ?


I think the access to data segments for global variables or static
vars should not be done through stack pointer ( which accesses the mem
of stack segment). I think the data segment should have its own data
structure...just guessing....I am also very excited to know the exact
answer..
 
Reply With Quote
 
Good Guy
Guest
Posts: n/a
 
      10-19-2010
On Oct 19, 7:40*am, Amarpreet Singh <(E-Mail Removed)> wrote:
> On Oct 19, 1:11*am, Good Guy <(E-Mail Removed)> wrote:
>
> > I know when it's a matter of accessing memory of a stack frame it'll
> > be through using stack frame pointer but I wonder about how the access
> > to data, BSS segments containing global/static data will be, through
> > using a pointer like stack frame pointer indicating starting point of
> > those segments or instructions address pieces of those segments
> > directly so that each time application starts the system will have to
> > write address parts of instructions in text segment ?

>
> I think the access to data segments for global variables or static
> vars should not be done through stack pointer ( which accesses the mem
> of stack segment). I think the data segment should have its own data
> structure...just guessing....I am also very excited to know the exact
> answer..


I didn't mean it might be through using exactly stack/stack frame
pointer, I meant a pointer with similar purpose.
 
Reply With Quote
 
Yakov Gerlovin
Guest
Posts: n/a
 
      10-19-2010
> how the access to data, BSS segments containing global/static data will be, through
> using a pointer like stack frame pointer indicating starting point of
> those segments or instructions address pieces of those segments
> directly so that each time application starts the system will have to
> write address parts of instructions in text segment ?


The addresses of global/static variables are resolved during linkage.
The calculated addresses are relative to the begging of BSS segment
and each time the application starts may reside at different physical
memory locations.

For example,On x86 real-mode, when application starts, the BSS
starting address will be stored in DS register.
Then, if one wants to access a global variable at offset 4 from the
beginning of BSS the compiler will generate something like
MOV AX,[0x04] which is equal to MOV AX, [DS:0x04] (Actual address
DS*16 + 4)
The offset 0x04 will be calculated at link time
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      10-19-2010
On Tue, 2010-10-19, Yakov Gerlovin wrote:
>> how the access to data, BSS segments containing global/static data
>> will be, through
>> using a pointer like stack frame pointer indicating starting point of
>> those segments or instructions address pieces of those segments
>> directly so that each time application starts the system will have to
>> write address parts of instructions in text segment ?

>
> The addresses of global/static variables are resolved during linkage.


During /linkage/ or during /loading/. E.g. on the Amiga, you had no
idea which addresses your BSS would end up in until you actually
loaded (tried to run) the program. Then you had at least two ways of
loading:

- keep a base address and do indirect addressing with offset to
access the various variables, or

- "write address parts of instructions" according to above.

The latter was generally considered less efficient, and prevented you
from sharing the same text segment between two running copies of the
same program.

> The calculated addresses are relative to the begging of BSS segment
> and each time the application starts may reside at different physical
> memory locations.


Not on modern Unixes though, and I'm guessing not on Windows either.
You have virtual memory, so an executable can (and will) contain the
exact addresses which are later used during runtime.

In this scenario the code /can/ contain hardcoded addresses ... but if
that's the most efficient on a certain architecture is a different
question.

The simplest way to check is to compile an example and look at the
generated code.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      10-20-2010
On Oct 18, 9:11 pm, Good Guy <(E-Mail Removed)> wrote:
> I know when it's a matter of accessing memory of a stack frame it'll
> be through using stack frame pointer but I wonder about how the access
> to data, BSS segments containing global/static data will be, through
> using a pointer like stack frame pointer indicating starting point of
> those segments or instructions address pieces of those segments
> directly so that each time application starts the system will have to
> write address parts of instructions in text segment ?


There are no real rules; it depends on the architecture. On
machines with direct addressing, it will typically resolve in an
instruction using the direct address. On other machines (many
risc architectures, for example), the generated code will load
the address into a register, and then access that. And it's
quite conceivable that the ABI reserves a register for this.

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cisco 340AP: Failed "Too Many Stations in BSS" tg Cisco 6 05-25-2008 08:21 PM
Heap & BSS karthikbalaguru C Programming 13 08-23-2007 09:17 AM
wat is .bss segment in object file jesjak@gmail.com C Programming 4 05-23-2007 07:54 PM
variable allocated from stack/bss ?? onkar C Programming 148 12-18-2006 07:22 AM
Learn: linking, small data area, bss, relocation ... termiflyer C Programming 4 10-10-2005 08:29 AM



Advertisments