Question:
A program written on assembly is machine dependent but a program written in Java ,python etc.. are not. why is?
Silvercat
2012-05-26 21:31:53 UTC
why is that? at the end don't they all get converted in to machine language? what is the difference?
Four answers:
Shadow Wolf
2012-05-26 23:28:51 UTC
Assembly language is usually specific to just one specific microprocessor. However, even the latest PC processors are backward compatible with older machine code. So the Intel X86 series is an exception as are others. Even machine code isn't always machine dependent.



Some higher level programming languages such as Python or Java are interpreted. Java is compiled into virtual machine code and it runs on a virtual Java machine which makes it compatible with any Java platform. Python is a little more restricted and will only run where there is an interpreter that is compatible. These are actually two examples of programming languages that never get compiled into machine code. So not all languages end up as machine code when they are run.



Other mid to high level languages such as C, C++, Pascal, Fortran and others are usually compiled to machine code. They are also somewhat platform independent as long as compilers exist on the different platforms. The up side of compilers is the machine code usually runs faster than interpreted programs.



There is a special class of programming languages which may run as interpreted languages or compiled into machine code. Where both compilers and interpreters exist for a language, you can have it both ways. Some versions of BASIC may be run as an interpreted language and compiled.



Last is emulation. With an emulator, you can run machine code for another computer just the same as you could run it on the original target computer. Some classics such as the Commodore 64 have emulators available and this allows you to run 6502 machine code on a PC. Similarly, computers such as the TRS-80 and Atari computers also have emulators available for them with Z-80 and 6800 processor emulation respectively. They are more than just microprocessor emulation since they reproduce the entire computer with most or all of it's original function.



Perhaps the thing to remember is none of the programming languages are really machine dependent or machine independent. A lot depends on what tools may be available for the computer.



Shadow Wolf
James Bond
2012-05-26 21:44:05 UTC
Assembly language and Machine languages are very specific to a particular HW platform. Thus, assemblers are also. No two processors will be having same assembly and machine language instruction sets. Thus, assembly language programs which we write in a specific machines say for instance Intel 3086 will run only on that machine or that machine specific assembler. Whereas high level languages such as Java, Python etc are not HW dependent. I mean the same program can be used on any machine. Only the compilers on the machines does the magic of converting high level language program to that HW specific machine language
Kasey C
2012-05-26 22:01:32 UTC
Program written in assembly or machine language are like a custom fitted shirt for a specific body.



Java is usually run through a "virtual machine". As long as the virtual machine are adapted to various real machines Java will run.



Python I believe is interpreted, so the interpreter itself must be adapted to the various real machines.



The general idea is the compiler / interpreter / virtual machine is machine dependent, so the language itself is not.
King Boy
2012-05-26 22:09:16 UTC
It is too obviously, assembly files once compiled to exe files are runnable only on some machine simply because the languages for different machine architectures are different. All programs of all languages once compiled into exe are also impossible to run on different machines of different architectures (machine dependent). But java doesn't compile the code files into exe files directly, it compiles them to intermediate files called bytecode files (.class), these files will be loaded into memory and run properly with the help of JIT (Just-in-Time) compiler, your java bytecodes are machine independent but your JIT compiler is machine dependent, yes if you use windows xp you need a version of JIT compiler for win xp, if you use mac os you need another version of JIT compiler for mac os...

On windows, these bytecodes will be compiled into exe, on mac os or any others, these bytecodes will be compiled into their own executable files (I don't know what they are called, maybe .cab?...)

Without that compiler, your bytecodes can't be executed.


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