Compilers

Discussion about everything. New games, 3d math, development tips...

Compilers

Postby Alpha Omega » Fri Jan 13, 2012 7:44 pm

Okay so I have been learning ASM, went with the NASM flavor just to get my feet wet with it. Now that I know how the C and ASM can interact, I have a question on the process of creating an .exe for this example win32.

So you write a C or C++ program in some fancy compiler. The compiler takes the source and runs various passes... and is one of those passes, taking the source to ASM code and then running an ASM assembler on that code to get machine code?

Isn't machine code CPU specific? If you compile a C++ program using an AMD processor can it run on an intel processor?

Does the win32 executable make it to machine code or just an assembler version?

I know C# exe's need the CLR to run them so they must be processor independent like java.

If you can give some incite, I would be happy to listen.
User avatar
Alpha Omega
 
Posts: 284
Joined: Wed Oct 29, 2008 12:07 pm

Re: Compilers

Postby CuteAlien » Fri Jan 13, 2012 8:22 pm

Check section 11 (How the compiler works) to find out about compile-stages: http://www.network-theory.co.uk/docs/gccintro/
That manual is about gcc, but other compilers work similar.

AMD always makes it processors Intel-compatible (and once in a while Intel even follows AMD). Which means they both have the same command-set and so you can run programs on both processors. But if you compile for example for newer processor features those would indeed no longer run on older processors. Bascially you don't program for the processor, but for the command-set and expect that each processor handles those commands correctly.

Win32 exectuables are machine code (as are the .obj files and .lib files are just a bunch of .obj files put together so they also contain machine code).

And yes, C# and Java compile to code for a virtual machine. Which basically means your code compiles to a command-set that looks similar like assembler-commands - except that the commands are just a standard and not optimized for a specific processor. So a virtual machine is basically simulating a processor and because you can run the simulation on different sytems you get independent of the real processor platform. It would also be possible to create processors which directly have a Java or .NET command-set, but the only reason to do that would be some optimization for Java or .NET (while completely killing compatibility to Intel, etc).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5359
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Compilers

Postby ACE247 » Fri Jan 13, 2012 8:41 pm

C++ compiler doesn't turn it into machine code when you compile for win32 as far as I know. It is sort of a low level code that still requires the operating system kernel to use/convert the appropriate machine code for your system. You can though compile for machine code with C++. As far as I know to run machine code the computer only needs to have the same type of instruction set (X86_64 or X86_32 etc...) as it was compiled for. Don't know how varying memory addresses are handled across machines though.
Most basic = Binary. Abstracted version of Binary = Machine code. Abstraction of that = Assembly. And then there's the massive abstraction of assembly to C/C++.
Obviously nothing is done as binary these days, the cpu automatically converts ASCII Instruction strings from Machine code to complex Binary, using its pre-determined Instruction set, so its not compiled as Binary. If this sounds like gibberish, It might be, I'm not entirely certain of all this anymore these days. (Only once read a ASM/Machine code book)
Honestly though I might also benefit from some enlightenment as to what exactly happens... :)
H8L6L5M4G3H5M7N8S7N9O1R8J1P5M7N9O4P2Q5R6T7U4M3N8X6S5T8W (If you want the secret, why not 'TRY' decrypting it? )
This Door's lock doesn't need a key, the Lock is the key to open the Lock and you don't know how to turn the key...
Link: My Blog :)
User avatar
ACE247
 
Posts: 695
Joined: Tue Mar 16, 2010 12:31 am
Location: Namibia

Re: Compilers

Postby Radikalizm » Fri Jan 13, 2012 8:54 pm

@ACE247:

Native code (ie. non-managed code) does compile to machine code, it's the compiler which takes care of integrating kernel functions in your application. Maybe you're thinking of the rings in x86 processors, where ring 0 is the level the kernel executes at and where ring 3 is where user applications run, but this is purely for protection purposes.
Also, machine code is just a sequence of processor instructions provided in said processor's ISA, it's not an abstraction of 'Binary code'. When you analyze them they'll probably be shown in hexadecimal format since binary is just a painful representation for human reading
Radikalizm
 
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: Compilers

Postby ent1ty » Fri Jan 13, 2012 9:02 pm

ACE247 wrote:... Honestly though I might also benefit from some enlightenment as to what exactly happens... :)

Sh!t happens.
True story.
Height2Normal - convert height maps to normal maps

Code with brain, not heart.
- entity, a proud member of the Heartless Coders society
ent1ty
 
Posts: 925
Joined: Sun Nov 08, 2009 11:09 am

Re: Compilers

Postby Alpha Omega » Fri Jan 13, 2012 9:31 pm

I was just thinking about high frequency computations for work and so it brought me to Wirth's Law. If anyone has any input here it would nice. My idea as a newbie, would be to try to bring higher level abstractions closer to the hardware.

For example, my plan is to create a kernel built to solve differential equations which can compile files and run it straight into the cpu without all the higher level overhead. Possibly, base the kernel on a very paralleled approach so any further abstractions can process threads at the lowest level.

As we approach the hardware barrier, in which computer hardware will have reached its theoretical maximum, will we begin trying to rethink the way we program?

Or are we simply going to adopt quantum computing? How will that impact software developement?
User avatar
Alpha Omega
 
Posts: 284
Joined: Wed Oct 29, 2008 12:07 pm

Re: Compilers

Postby ACE247 » Fri Jan 13, 2012 10:30 pm

Thanks for the info guys! Yeah I must have been lost somewere with execution rings. Though I did once try coding one of those 8080 Chips from an apple 2board in Hex Machine instruction code, though luckily soon after I learned C++, probaly more usefull eh? :)
Quantum Computing = Low Level Code debugging nightmare :D As I've heard.
H8L6L5M4G3H5M7N8S7N9O1R8J1P5M7N9O4P2Q5R6T7U4M3N8X6S5T8W (If you want the secret, why not 'TRY' decrypting it? )
This Door's lock doesn't need a key, the Lock is the key to open the Lock and you don't know how to turn the key...
Link: My Blog :)
User avatar
ACE247
 
Posts: 695
Joined: Tue Mar 16, 2010 12:31 am
Location: Namibia

Re: Compilers

Postby Radikalizm » Fri Jan 13, 2012 10:49 pm

ACE247 wrote:Thanks for the info guys! Yeah I must have been lost somewere with execution rings. Though I did once try coding one of those 8080 Chips from an apple 2board in Hex Machine instruction code, though luckily soon after I learned C++, probaly more usefull eh? :)
Quantum Computing = Low Level Code debugging nightmare :D As I've heard.


Don't know whether it's a nightmare, but I could imagine it being one for a 'conventional' programmer since you'd be working with qubits, which can hold values of '0', '1' and '0 and 1' (caused by the principle of superposition if I remember correctly). It'd just be a completely different way of working compared to current computers
Radikalizm
 
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: Compilers

Postby ACE247 » Fri Jan 13, 2012 11:29 pm

Actually the programming occurs on normal computers, the way the algorithms are written to the qubits though is the tricky part, and its presently also the biggest limiting factor in the usability and speed of quantum computers, though recently one did a Ramsey 2 colour equation in 270milliseconds and gave the correct answear of 8. :)
But heck nowadays to be a programmer you don't even have to really understand the fundamentals of all the technical bits going on in a processor.
Thats all going to change again with quantum computing, but once quantum becomes the norm we are probably going to end up with something like Q++ one day!

EDIT: Oh and I BET a quantum computer couldn't even crack that encryted string in my signature, self made and quite ridiculously simple Encryption that I used and Its 100% decipherable! IF you know how, its actually encrypted with itself and the ingeniuos thing is its reversible from the text you see there, and completely impervious to language consonant matching etc, maybe even brute force... :D I've been laughing since the day I came up with it, even challenged some cryptanalysts with it.
H8L6L5M4G3H5M7N8S7N9O1R8J1P5M7N9O4P2Q5R6T7U4M3N8X6S5T8W (If you want the secret, why not 'TRY' decrypting it? )
This Door's lock doesn't need a key, the Lock is the key to open the Lock and you don't know how to turn the key...
Link: My Blog :)
User avatar
ACE247
 
Posts: 695
Joined: Tue Mar 16, 2010 12:31 am
Location: Namibia

Re: Compilers

Postby aaammmsterdddam » Sat Jan 14, 2012 10:16 pm

I am assuming it isn't possible to decrypt due to the string length being the same as the length of the key?
I read some on that it is apparently impossible to crack.
(n^(n-n))-1
aaammmsterdddam
 
Posts: 520
Joined: Mon Oct 24, 2011 10:03 pm


Return to Off-topic

Who is online

Users browsing this forum: No registered users and 1 guest