Click here to Skip to main content
15,882,017 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Compilers Pin
Dave Kreskowiak2-Feb-23 10:08
mveDave Kreskowiak2-Feb-23 10:08 
GeneralRe: Compilers Pin
trønderen2-Feb-23 12:41
trønderen2-Feb-23 12:41 
GeneralRe: Compilers Pin
Dave Kreskowiak2-Feb-23 12:43
mveDave Kreskowiak2-Feb-23 12:43 
GeneralRe: Compilers Pin
jschell3-Feb-23 5:17
jschell3-Feb-23 5:17 
GeneralRe: Compilers Pin
Calin Negru2-Feb-23 21:29
Calin Negru2-Feb-23 21:29 
GeneralRe: Compilers Pin
Dave Kreskowiak3-Feb-23 11:32
mveDave Kreskowiak3-Feb-23 11:32 
GeneralRe: Compilers Pin
trønderen3-Feb-23 12:40
trønderen3-Feb-23 12:40 
AnswerRe: Compilers Pin
trønderen2-Feb-23 13:54
trønderen2-Feb-23 13:54 
Usually, a machine instruction is a word of, say, 32 bits. The first 6 to 8 bits (typically) tell what this instruction does: Move data, jump to somewhere, add two values etc. The next few bits may indicate how you go about finding the operand, i.e. what to move, where to jump or which value to add. The interpretation of the following bits depend on those (often called the 'address mode' bits): Either as a register number, how far to jump, or the value to add. If the address mode bits so says, maybe the value to add is not in the instruction itself, but the instruction tells in which register you can find the address of the value to add.

The compiler breaks down your code in more primitive operations, such as "add the value of X", without being concerned about what the proper machine instruction will look like. Not until it gets down to the very bottom, the 'code generator'. A compiler may provide different code generators for different machine types. A given code generator knows what an 'add' instruction looks like on x64 processors, knows the proper address mode bits and how to put the address of X into the instruction. Another code generator, for ARM, knows another code for ADD on the ARM, but it also knows that you cannot directly add something in memory. First the code generator must look up an unused register (and if there is none, it must generate an instruction to flush the value in one register back to memory to free it up), then generate an instruction to load X into the free register, and then generate an instruction to do the actual add of the newly loaded value.

There is no common, standardized code for neither move, jump nor add on different machines. The code generator knows the codes for this machine. You may tell the compiler to switch to another code generator knowing the codes for another machine (that is commonly referred to as 'cross compiling'), but the program that comes out of it cannot be run on this machine; you must copy it to another machine of the right type to run it.

In the good old days, there were dozens of different machine types out there, each with its own instruction codes. The last 35 years or so, the 'x86' has pushed most others out. Every PC in the world can understand x86 codes.

But x86 is for 32 bit machines! 64-bit PCs understands 'x64' codes (and address modes), which are different! If you want that move, jump or add to work on a 64-bit PC, your compiler must select a code generator knowing the proper codes for x64. The program will not work on an old x86 PC.

Relax ... The x64 CPUs can be told to forget the x64 codes, and run the x86 instead. The .exe file tells which instruction set should be activated, so you can run 35 year old programs on your brand new 64 bits PC (provided that your current OS will honor all the requests made by that old program, which is not guaranteed - but 20-25 years is probably on the safe side).

Then, what about your smartphone - will it know x64 move, jump or add instruction codes? No. Will it know x86 instruction codes? No. You have to ask your compiler to use the code generator that makes ARM instruction codes. ARM has 32 bit and 64 bit codes too, that are different ... Besides: If your program was written for Windows, it expects that is can ask the OS (i.e. Windows) for this and that service - and Android says Huh?? The services provided by Android are quite different.

Bottom line: The rosy, cosy days when x86 worked everywhere are over.

Then comes dotNet. When a dotNet 'assembly' (informally you may call it a module) is loaded into your machine, smartphone or whatever, you'll see an incompletely compiled program: The compiler has left a message: Here I should have generated the code for adding the value of X, but I didn't know what kind of machine this will be running on! So please, before running this program, generate the proper instructions for adding X, will you?

dotNet for a given machine has the proper code generator for that machine. dotNet on an ARM32 generates ARM32 codes, dotNet on an ARM64 generates ARM64 codes, dotNet on a 64 bit PC generates x64 codes. They are all different.

For now, Windows itself is not dotNet, so it must be compiled separately for every machine architecture. A growing number of applications are dotNet, incompletely compiled, and the last step of compilation, code generation, is not done until you know for sure which codes to use, just in time for execution. So the dotNet code generator is frequently referred to as the "just in time compiler", or "jitter".

ps.
If you want to look at instruction codes and addressing modes and such to see what they are like, my recommendation is to stay away from x64 and x86. They are both a mess, having grown and been extended and grown more and been extend ... into a crow's nest. ARM64 (aka. Aarch64) is certainly not the simple, easily understood thing that the early 32 bit ARMs were, yet it has retained a much more manageable structure.
GeneralRe: Compilers Pin
Calin Negru2-Feb-23 22:27
Calin Negru2-Feb-23 22:27 
GeneralRe: Compilers Pin
Richard MacCutchan2-Feb-23 23:16
mveRichard MacCutchan2-Feb-23 23:16 
GeneralRe: Compilers Pin
Calin Negru4-Feb-23 5:47
Calin Negru4-Feb-23 5:47 
AnswerRe: Compilers Pin
jschell3-Feb-23 5:21
jschell3-Feb-23 5:21 
AnswerRe: How it came to be. Pin
Jeremy Falcon6-Feb-23 9:11
professionalJeremy Falcon6-Feb-23 9:11 
GeneralRe: How it came to be. Pin
jsc426-Feb-23 23:14
professionaljsc426-Feb-23 23:14 
GeneralRe: How it came to be. Pin
Jeremy Falcon7-Feb-23 3:25
professionalJeremy Falcon7-Feb-23 3:25 
AnswerRe: Compilers Pin
BernardIE53179-Feb-23 8:51
BernardIE53179-Feb-23 8:51 
QuestionMessage Closed Pin
1-Feb-23 14:01
Member 149687711-Feb-23 14:01 
AnswerRe: English , please.... Pin
Victor Nijegorodov1-Feb-23 20:25
Victor Nijegorodov1-Feb-23 20:25 
QuestionRe: English , please.... Pin
CPallini1-Feb-23 20:50
mveCPallini1-Feb-23 20:50 
AnswerRe: English , please.... Pin
Richard MacCutchan1-Feb-23 21:07
mveRichard MacCutchan1-Feb-23 21:07 
AnswerRe: English , please.... Pin
Calin Negru2-Feb-23 1:03
Calin Negru2-Feb-23 1:03 
AnswerRe: English , please.... Pin
Gerry Schmitz2-Feb-23 6:57
mveGerry Schmitz2-Feb-23 6:57 
GeneralRe: English , please.... Pin
Richard MacCutchan3-Feb-23 1:08
mveRichard MacCutchan3-Feb-23 1:08 
AnswerRe: English , please.... Pin
k50542-Feb-23 9:18
mvek50542-Feb-23 9:18 
QuestionClang/LLVM support in Visual Studio projects Pin
ForNow31-Jan-23 10:25
ForNow31-Jan-23 10:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.