Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Misconception of Languages  (Read 5128 times)

0 Members and 1 Guest are viewing this topic.

progmer

    Topic Starter


    Rookie

    Misconception of Languages
    « on: July 22, 2014, 07:26:03 AM »
    Hi there,
    please correct me if I have any misconception below:

    So, a machine language can be worked directly by a hardware ( processors , etc ) without further translation or compilation.
    But, machine language differs for different hardware ( AMD processor, Intel processor ). Different hardware requires slightly different method to program using its machine language.
    C++ or other High-Level languages require a Compiler to translate the scripts into a computer understandable code ( Machine Language ).


    Since machine language differs for different hardware, does this means I can't compile a program that can run on every computer?

    Or maybe I need to recompile the program on other computers just to make sure they can run?

    Does C++ and other High-Level languages specially engineered such that it could compile a written program into many other kinds of machine language and how does it make the right choice?

    What kind of file extension is used for the machine language? Is it .exe? Or is it different for different Operating System?

    Since a machine language is used for targeted hardware only, why would a machine language extension being effected by Operating System?

    Thank you for helping me out!!

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Misconception of Languages
    « Reply #1 on: July 22, 2014, 10:43:19 AM »
    So, a machine language can be worked directly by a hardware ( processors , etc ) without further translation or compilation.
    But, machine language differs for different hardware ( AMD processor, Intel processor ). Different hardware requires slightly different method to program using its machine language.
    C++ or other High-Level languages require a Compiler to translate the scripts into a computer understandable code ( Machine Language ).
    This is correct. "Machine code" is the data used directly by the processor. Assembly Language is a symbolic representation of this machine code- you didn't mention Assembly, but I think it's worth mentioning. Assembly is the closest a person should get to machine code unless they have no choice.

    Quote
    Since machine language differs for different hardware, does this means I can't compile a program that can run on every computer?
    You are correct. a program compiled for an x86 CPU will not run on a ARM; a program compiled for a ARM will not run on an x86, etc. However there is a case that may be worth mentioning- some languages are compiled not to machine code, but rather to an Intermediate language or bytecode, and that intermediate language or bytecode get's run by a "Virtual Machine", rather than being run directly by the hardware.

    Quote
    Or maybe I need to recompile the program on other computers just to make sure they can run?
    Essentially, yes. Excepting when you are compiling to a intermediate language as described above (Java or .NET, for example).

    Quote
    Does C++ and other High-Level languages specially engineered such that it could compile a written program into many other kinds of machine language and how does it make the right choice?
    When you run a C++ Compiler, it compiles for the architecture it is running on or a compatible architecture, typically. At any rate compilers need to be written specifically for every single architecture that is intended to be compiled to. This is why C is so ubiquitous across different platforms- it is a fairly simple language and it's control structures and capabilities are easier to create compilers for.

    Quote
    What kind of file extension is used for the machine language? Is it .exe? Or is it different for different Operating System?
    machine language doesn't have a file extension. It can be present in any number of files. an .exe for example could include machine code, or it could include bytecode, or P-Code, or any number of things.

    Quote
    Since a machine language is used for targeted hardware only, why would a machine language extension being effected by Operating System?
    I'm not sure what you are referring to, but the best I can guess is perhaps referring to how you cannot run 64-bit programs when you are running a 32-bit OS?

    A modern x86 processor is, in some ways, really several processors in one. the latest i7 is fully software compatible with the original IBM PC 8088 instruction set- you can boot from a DOS floppy just like you did in 1983. Effectively what Intel (and AMD) do is add new enhancements into new operating modes. As an example, 32-bit Protected mode is the mode of operation required to run 32-bit programs. So when you run a 32-bit OS, Windows switches the CPU into 32-bit protected mode, allowing it to run 32-bit code as well as utilize the features of the 32-bit Processor.

    running 64-bit code requires that the CPU be in what is referred to as "64-bit Long mode" but may as well just be called 64-bit protected mode. It's basically the same idea as 32-bit protected mode, with enhancements and new features added to the new mode to prevent introducing possible compatibility problems with old software.

    It should be obvious now why running a 32-bit OS on a 64-bit platform prevents 64-bit programs from being run. It is because in that case even though the hardware is 64-bit, because it is running a 32-bit operating system and that 32-bit operating system switches to 32-bit protected mode and assumes and uses the system as if it is in fact just 32-bit, no 64-bit code can be run.
    I was trying to dereference Null Pointers before it was cool.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Misconception of Languages
    « Reply #2 on: July 22, 2014, 10:53:44 AM »
    A history of the development of the computer will show that the purpose of a hug-level language was to make it easier for humans to program machines.

    This first computer I built did not have a loader in ROM. Instead, I have to enter the code with a row  of switches that represented the binary code for each instruction.  Unable to memorize the sequence e, I have to use a written list of numbers to help me set the binary codes. So the loader in programmed by hand would then read a high-level language from a tape. The high-level language let me use a console to write programs in BASIC.
    Those were the old days.