User
User

Reputation: 1

Where does the stack and machine instructions reside in memory?

Whenever I use gdb on my programs (32bit, red hat linux), I see that the addresses used in the registers are extremely far away from the addresses that has been linked to the machine instructions.

Using a simple "hello world program"

0x080483a4 <main+0>:    lea    0x4(%esp),%ecx
0x080483a8 <main+4>:    and    $0xfffffff0,%esp
0x080483ab <main+7>:    pushl  -0x4(%ecx)
....

where the info registers command produces

esp            0xffffb970   0xffffb970
ebp            0xffffb978   0xffffb978
esi            0x9d5ca0 10312864
edi            0x0  0
eip            0x80483b5    0x80483b5 <main+17>

Those esp and ebp shows a frame very different location from where the code is located.

What I think is that...

in the 4gb ram stick, there are 2^32 memory locations, the stack is located more in the top part (where it's 0xFFFFFFFF) and grows down and things like these hello program, the OS itself, other currently running programs are at the bottom and grow up (so it starts at 0x00000000), right beneath the heap which is also on the opposite side of where the stack is.

I'm probably wrong, but I was hoping to get an answer from you guys.

Also, is there more info on what's going on with the rest of the memory? Is there a course/book that covers broad questions similar to what I just asked? I feel like I have to fill in alot of gaps with what's going on in my intro assembly language class.

Thank you.

Upvotes: 0

Views: 459

Answers (1)

stark
stark

Reputation: 13189

Unless you have a time machine and go back to the 1960's all addresses that you see are virtual addresses. They could be right near each other in physical memory but still one has a high address and the other low. If your OS is allocating 4K pages, only the low 12 address bits are not mapped by hardware.

Upvotes: 4

Related Questions