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

G

Good Guy

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 ?
 
R

red floyd

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.
 
A

Amarpreet Singh

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..
 
G

Good Guy

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.
 
Y

Yakov Gerlovin

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
 
J

Jorgen Grahn

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
 
J

James Kanze

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top