School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,124 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,007 people online right now. Registration is fast and FREE... Join Now!




How do computers calculate the proper address?

 

How do computers calculate the proper address?

nfsmw222

3 Sep, 2009 - 08:35 AM
Post #1

New D.I.C Head
*

Joined: 27 Jul, 2008
Posts: 3

Honestly, I don't know if this is the right place to ask a question like this but at least it's worth the try.

I've been wondering about this: When write your code and declare your functions and variables, obviously you refer to them by their name so the machine does exactly which one are you about to access or execute or so, but after compilation does your variable/function names "disappear" and be replaced by an offset address in the compled exe, dll ? Also your executable is loaded to a different part or the memory so their physical address can be very different every time you load your exe, and I suppose that the function addresses are resolved using the address of the first byte of the executable, and the adding the offset, is that correct, at all? Besides that, what happens exactly when your memory is fragmented, and say you don't have a single block of continuous memory where you can "fit" your executable into, does the executable become fragmented as well?

If yes, how does the computer resolve function and/or variable addresses, since addig the offset will not give the correct address, it has to keep track of the fragments as well.

If no, then it can't execute your program at all, right?

I'd be happy if someone knows the answer, because I'm very curious about this.

Thx


User is offlineProfile CardPM
+Quote Post


Kanvus

RE: How Do Computers Calculate The Proper Address?

3 Sep, 2009 - 08:15 PM
Post #2

D.I.C Regular
Group Icon

Joined: 19 Feb, 2009
Posts: 451



Thanked: 39 times
Dream Kudos: 50
My Contributions
Many things in memory, after being converted from code to an EXE, doesn't always exactly lose its names. They become translated into a context that assembly understands. For example an If statement or nest could be translated into a pattern of short jumps and long jumps in assembly and your integers are kept as register values. Everything is there but in another readable language.

When things jump around they either know the address to jump to, or like you said, jump a certain amount of spaces from where it already is as an offset.
User is offlineProfile CardPM
+Quote Post

Oler1s

RE: How Do Computers Calculate The Proper Address?

4 Sep, 2009 - 02:12 AM
Post #3

D.I.C Addict
****

Joined: 4 Jun, 2009
Posts: 733



Thanked: 69 times
My Contributions
QUOTE
but after compilation does your variable/function names "disappear" and be replaced by an offset address in the compled exe, dll ?
Yes. Names are high level concepts. Just like what a programming language is in the first place. It's a bridge between programmers and computers. Neither humans and computers directly know it. Humans expend time learning this language. For computers, a set of more programs convert that code in that language to something that the operating system and the processor understand.

Processors don't deal with names.

QUOTE
Also your executable is loaded to a different part or the memory so their physical address can be very different every time you load your exe, and I suppose that the function addresses are resolved using the address of the first byte of the executable, and the adding the offset, is that correct, at all?
It's more complicated, so neither a yes nor no answer makes sense. It's also OS and architecture dependent, actually. The best way to really understand these details is to look at the resources involved in learning Assembly (probably x86 assembly, Windows OS, for you), not because Assembly is the enlightening answer, but because at that limited level of abstraction, you are exposed to the relevant information.

QUOTE
Besides that, what happens exactly when your memory is fragmented, and say you don't have a single block of continuous memory where you can "fit" your executable into, does the executable become fragmented as well?
Again OS dependent. And part of learning Assembly or OS design is that you understand common strategies for memory handling. Overall, what you'll learn is that, yes, in physical memory, the program is commonly spread out in fragments.

QUOTE
If yes, how does the computer resolve function and/or variable addresses, since addig the offset will not give the correct address, it has to keep track of the fragments as well.
By doing additional bookkeeping. That expensive OS you buy has a system of managing memory. There's several abstractions going on here. There's what memory looks like in say, C, C++, Python, etc.. Then there's memory according to how the OS presents to various programs. And then there's physical memory. The OS will manage physical memory, and present it in a uniform manner to programs. In fact, your processor does some additional memory management too (caching).

I know the answer isn't useful, but this is a question that's resolved in a single forum post. You'll have to delve into books and a good bit of technical reading to really understand all that's going on behind the scenes.
User is online!Profile CardPM
+Quote Post

Aeternalis

RE: How Do Computers Calculate The Proper Address?

4 Sep, 2009 - 02:55 PM
Post #4

D.I.C Regular
***

Joined: 13 Jul, 2009
Posts: 273



Thanked: 25 times
My Contributions
great coverage by Oler1s.

thought I would drop you a link for further clarification on Operating System memory management.

Page Tables

It's a complicated topic and can take a while to get your head around it. Fortunately unless your using a low level language, you won't need to know too much about it. This article can give you a quick look at the guts of it along from one implementations perspective. Other implementations are going to be similar.


Aet

This post has been edited by Aeternalis: 4 Sep, 2009 - 03:01 PM
User is offlineProfile CardPM
+Quote Post

nfsmw222

RE: How Do Computers Calculate The Proper Address?

5 Sep, 2009 - 01:36 AM
Post #5

New D.I.C Head
*

Joined: 27 Jul, 2008
Posts: 3

Wow! very good posts.
Thank you very much for your help rolleyes.gif
User is offlineProfile CardPM
+Quote Post

debjit625

RE: How Do Computers Calculate The Proper Address?

6 Sep, 2009 - 03:44 AM
Post #6

D.I.C Regular
Group Icon

Joined: 6 Sep, 2008
Posts: 340



Thanked: 30 times
Dream Kudos: 50
My Contributions
You have to know about the working real mode and protected mode to get your answer and Yes the names of the variables are converted into file offset in the exe file and when you executes it the OS maps(called mapping)the file in memory(RAM) and assign the physical address of every data.At right this moment it is a little hard to understand for you about this.First learn about real mode and protected mode operation and offcourse about PE file structure (.Exe) and more important is Assaembly you will get all your answer.

Good Luck

This post has been edited by debjit625: 6 Sep, 2009 - 04:05 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:06PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month