Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How the PC compiler knows

Status
Not open for further replies.

zainka

Full Member level 2
Full Member level 2
Joined
Nov 18, 2004
Messages
137
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,298
Location
No(r)way
Activity points
1,659
Hi

Beeing an embedded sw writer I have a fundamental question according to how a PC (for DOS /Win) and a compiler for such a platform are cooperating to make a program.

When writing a program for an embedded platform like a microcontroller, the compiler for this platform knows exactly where to place variables and constant for the program i write and I can find the correct address and location by looking into the generated suport files like tha map file or I can even defne these locations my self.

However, this is not the case with DOS programs (for exampel), at compiling time you do not know where in ram your variables and constants are placed and so on. How does the program know at running time where to find its variables?

I/O resources like the PCI bus and printerports and so on has well defined addresses like on embedded systems since this is defined by the prefferences the board manufacturers has to follow. But the rest?

I guess the PC compiler must add something like an init section at the beginning of the pc programm written by me (like the compiler for embedded systems also do, i know that) which talks to the OS running on the PC, but how is the things working in real (bad) life. A bad tutorial will do well for me at this point since, obviously, I know nottingh aboute this topic, and my english is bad too.

Thanks in advance for wathever you bring
Regards
Vidar(Z)
 

If the compiler generates relative indexing code, it's not problem. You set an address on an address register and use it as a reference. Put the start of your data section on A0 (I'm using the MC68000 as my model). Then the data 20 bytes away would be referenced as 20(A0) or something like that (it's been a few years).
Absolute memory references are a problem. The compiler (or linker?) needs to generate a header file of these memory locations. The loader then goes through the executable code and adjusts the absolute memory addresses to the actual memory locations. On Pentiums and other devices with virtual memory mapping it may be done quite differently.
I remember when I saw a compiler that would gnerate 'modules' of executable code that could be no longer that 32K in size. I knew right away it was generating code with 16 bit relative indexing mode only, which was the smart thing to do (again, it was on a 68K platform - my old Amiga).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top