Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

program execution

Status
Not open for further replies.

Ashford

New Member
hey guys,
I was thinking about executable formats and from what i understand, the executable file stores the raw machine code to be loaded into the "code segment" when the program is run. So if I compile a program to add two numbers using windows and then compile the same program using Linux(without the use of header and libraries), does that mean that the exact same machine code will be place in the part of the file that stores the machine code? I know that executable files contains other parts such as headers that will be unique to each format but will the machine code part of these two programs be the same and also will any other part be the same?
 
hey guys,
I was thinking about executable formats and from what i understand, the executable file stores the raw machine code to be loaded into the "code segment" when the program is run. So if I compile a program to add two numbers using windows and then compile the same program using Linux(without the use of header and libraries), does that mean that the exact same machine code will be place in the part of the file that stores the machine code? I know that executable files contains other parts such as headers that will be unique to each format but will the machine code part of these two programs be the same and also will any other part be the same?

It is possible that the code emitted will be identical (especially for something as simple as just adding two number) but generally not very likely unless you're using the same compiler with the same settings--and even then you will probably find differences as the code gets more complex. Compilers typically optimize the heck out of your code and you can't always predict how that will work without becoming insanely familiar with your compiler. Different compilers use different optimizations, and even the same compiler may well make different decisions based on architecture, OS, the market price of lobster. . .

So in a nutshell: maybe, for a very simple case, but unlikely in the general case.


Cheers,

Torben
 
Just wanted to add this to Torben's excellent reply.

Assemblers generate 1 machine instruction per opcode. There is a 1 to 1 mapping. So if you have either the ASM or the assmebled HEX(bin) file you can get one from the other. Note that you will not have the original names in an ASM file generated from HEX because the labels do not exist in the HEX file.

A single line of compiled code can generate many opcode (or machine instructions). Each compiler is free to use any sequence of opcodes that will provide the functionality of the source line. So not only are compilers not one to one, but they will most often fail to agree with each other. Torben covers this issue well.
 
i was actually suggesting that the OS be the only variable(i.e. architecture, compiler, compiler setting, etc stayed the same) but this really clears things up. thanks a lot :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top