Question:
Question on programming languages?
anonymous
2011-02-27 11:18:12 UTC
Hi,
I am a bit confused about programming languages. I have started programming lessons. But i confuse some things.

The source code is compiled by the compiler. It is compiled to what? A low level languages? Whom?

What is machine code?

We have learnt in IT in school that computers store data in binary. When i open an application (.exe) in a text editor i only see some "random" characters, what are these characters? Where is the binary, how can i see it?
Four answers:
Blackcompe
2011-02-27 11:47:12 UTC
Yes, source code is compiled by a compiler to a low-level language. Depending on the language of the source code, "low-level" can mean several things.



In Java, source code is compiled to byte code (a class file). Byte code is not machine code. It can't run as is on the hardware. It must be interpreted by the Java virtual machine (JVM). The JVM emulates the hardware for the byte code, just like virtualization technologies (VMWare, Virtual PC, Zen) does for guest operating systems. The JVM is written in C, and it does run natively on the hardware. The same goes for .NET languages, Perl, Python, PHP, etc. They're all interpreted languages.



In C and C++, gcc, the GNU compiler, compiles source code into machine that's specific to your machine. Different machines have different instruction sets (SPARC, MIPS, IA32, x86-64, PowerPC). You have to download the right gcc port for your machine and OS, since operating systems also use different file formats (ELF in linux and EXE in windows).



The byte code in Java resembles assembly language. The code is still human readable, but a bit more cryptic than your usual high-level language. A class file looks something like this:



move A0, S1;

add A0, 1;

.

.



Whereas, machine code is simply binary:



0101010101101001010

1010001010110010101

0101010101010101001



If you were to open an executable file you would see gibberish, because the bytes stored in memory could be a piece of data (a character, integer) or a processor instruction. A text editor is simply taking each byte and mapping it to it's ascii equivalent. Some of the bytes have no equivalent (like a processor instruction). So, you get those weird looking boxes that indicate the character is undefined. A text editor expects that the file your trying to open contains ascii or unicode characters. I've never tried opening a binary file, but I would try using a hex editor. A hex editor will show you the code in hexadecimal, from which you could easily, determine the binary equivalent using a hex-to-binary internet calculator.
green meklar
2011-02-27 13:41:06 UTC
>The source code is compiled by the compiler. It is compiled to what? A low level languages? Whom?



It depends. Something like C or C++ will be compiled to machine code. It is likely that it will be compiled to Assembler first, and then the Assembler code will be translated into machine code. However, there are also weird languages like Java, Java does not compile to machine code but rather to something called 'Java bytecode', which is executed using the JVM (Java Virtual Machine).



>What is machine code?



It is the raw program code that the computer's processor can understand and execute.



>We have learnt in IT in school that computers store data in binary. When i open an application (.exe) in a text editor i only see some "random" characters, what are these characters? Where is the binary, how can i see it?



You can use a hex editor, there is one available here:

http://www.hexedit.com/

It may not actually show the binary, but it will show hexadecimal, which is close (each hexadecimal character translates to a sequence of exactly four binary characters, in a very simple way). Converting the hexadecimal to binary is relatively easy. Here is a small Javascript address bar program that does something similar:



javascript: function g() {var t=prompt("Enter a hexadecimal sequence:"); var r=""; var e=""; var m=t.length; var i; var s; for(i=0;i


However, generally speaking you do not look at the contents of EXE files. There is hardly ever any point in doing so, because understanding the contents is usually close to impossible for a human. You can do slightly better by using a program called a 'decompiler', which can turn an executable back into Assembler code. These are often quite fallible though, because different architectures use different machine code and Assembler.
anonymous
2011-02-27 11:29:56 UTC
Depending on the language, the source code is compiled to machine code, object code or a lower-lvel high-level language. (ATLAS, for example, is compiled into BASIC.)



Machine code is the bits that actually run in the computer. If it's printing an upper-case A, for example, it would have 01100101 somewhere in the program. That value, when sent through s few processes, results in an A on the screen.



The characters are the ASCII equivalents of the binary values. To see it as binary you need a program called a hex editor, like XVI21 http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm (Raw disk editors are rare with Windows, but that would do it too.) But don't expect to see anything you can read, except text stored in the program. You'll see the data in hex (base 16 arithmetic) instead of binary (base 2 arithmetic), but whether you see it as 5 or as 101, it's still the number of fingers on one hand, and there are 64 or 1100100 pennies to the dollar.



Learning the opcode set of a CPU well enough to read machine code takes a long time, there's no reason to do it and VERY few people can. (I used to, with 8080, Z-80, 6800 and 6502 CPUs, I only know a tiny subset of x86, because I don't need to know machine code.)
doiron
2016-09-09 07:42:24 UTC
He possibly looking to say that you just have got to be trained programming approaches and good judgment, as an alternative than languages. This relatively is foremost, too. For illustration, being competent to keep a talk in 15 human languages does not imply you'll write an brilliant paintings of literature in any of them; and a relatively good written application is similar to a relatively good written booklet, in that it demands to have many constituents that are compatible in combination in non-noticeable however mighty approaches.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...