-1

Compiler convert human understandable language into machine level language. Can't we just write a program in machine level language so that it will be easy and quick for a program to execute.

Habi
  • 161
  • 1
  • 9
  • Just realised this question has nothing to do with Unix & Linux, I haven't the authority to mark it down. – X Tian Nov 08 '13 at 18:11

3 Answers3

2

Yes, you can program in assembler under Linux.

Check this and this questions on Stack Overflow, for example. Also, the Linux Assembly HOWTO looks good.

Community
  • 1
  • 1
Renan
  • 462
  • 7
  • 24
1

Compiler convert human understandable language into machine level language. Can't we just write a program in machine level language so that it will be easy and quick for a program to execute.

No one writes programs in machine language. Normal binary exectuables are not just machine code anyway, so it would be pointless to try and do this. Binaries contain machine code but include specific, OS dependent formatting. For example, linux uses ELF. This format is understood by the linker and loader (on *nix, the loader is part of the kernel). The only place unadulterated machine code exists is in the system memory.

You can write programs in assembly language, which is very similar to machine language, but then this must be compiled and linked. In other words, it is the same thing as writing a program in any other compiled language.

Finally, creating a binary manually by formatting some machine code would not provide any advantages and it would be an endless headache to work with. You might do it as a learning excercise, but not for any real purpose.

CodeClown42
  • 11,194
  • 1
  • 32
  • 67
  • Then how are compilers built so that they can communicate with machine level language. There must be some language. –  Nov 08 '13 at 18:37
  • Because compilers are themselves compiled. They run as machine code in memory executed through the processor, just like *EVERY* other process. That's the significance of machine code. It is the only thing that actually runs on the hardware. – CodeClown42 Nov 08 '13 at 18:43
  • The very first compilers were written in assembly. Since then, compilers usually compile themselves, and when ported to a new machine, we use cross compilation: teach a compiler how to write code for a new machine, then compile the compiler with that. This is how C is brought to new machines. And then, most high level languages themselves are written in C. Eg, python, java, perl, etc. – Max Nov 08 '13 at 19:12
0

Yes, but then you have to write more and then it takes longer, so using a higher level language and compiler is more efficient on your time. More often than not, a compiler is better than what a mere human can do (they are pretty good programmers these compiler writers).

X Tian
  • 766
  • 7
  • 13
  • I just asked this so i can know how all this programing language got evolved from null to this level. I still wonder how coding is done in this piece of solid. –  Nov 08 '13 at 18:39
  • Programming languages / instructions sets are designed *before* the machines that run them, and one definition of "computer" is a machine that can execute a *Turing complete* language (see http://en.wikipedia.org/wiki/Turing_completeness). This concept is what has made the evolution of higher level languages possible -- ponder the 3rd paragraph: *"the terms 'Turing complete' or 'Turing equivalent' are used to mean that **any real-world general-purpose computer or computer language can approximately simulate any other real-world general-purpose computer or computer language.**"* – CodeClown42 Nov 08 '13 at 18:57
  • Since any Turing complete language (such as asm or machine code) can be used to simulate any other turing complete language (nb: they all are, by design, Turing complete), you can compile C code into assembly and assembly into machine code, etc. – CodeClown42 Nov 08 '13 at 18:59