Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Access to data, BSS segments will be through using a pointer or byintructions directly addressing ? (http://www.velocityreviews.com/forums/t735860-access-to-data-bss-segments-will-be-through-using-a-pointer-or-byintructions-directly-addressing.html)

Good Guy 10-18-2010 08:11 PM

Access to data, BSS segments will be through using a pointer or byintructions directly addressing ?
 
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 ?

red floyd 10-18-2010 10:31 PM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
On Oct 18, 1:11*pm, Good Guy <pooria...@gmail.com> 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.


Amarpreet Singh 10-19-2010 04:40 AM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
On Oct 19, 1:11*am, Good Guy <pooria...@gmail.com> 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..

Good Guy 10-19-2010 06:44 AM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
On Oct 19, 7:40*am, Amarpreet Singh <singh.amarpr...@gmail.com> wrote:
> On Oct 19, 1:11*am, Good Guy <pooria...@gmail.com> 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.

Yakov Gerlovin 10-19-2010 08:11 AM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
> 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

Jorgen Grahn 10-19-2010 08:42 PM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
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 .

James Kanze 10-20-2010 10:57 AM

Re: Access to data, BSS segments will be through using a pointer orby intructions directly addressing ?
 
On Oct 18, 9:11 pm, Good Guy <pooria...@gmail.com> 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


All times are GMT. The time now is 06:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.