Search code examples
compiler-constructioncompilationbinary

how a source code is converted into 1's and 0's?


computers do not understand anything except one's and zero's.But I want to know the details how a source code or an instruction set is converted into 1's and 0's.Is the exe file only contains 1's and 0's?


Solution

  • Each type of operation in a microprocessor's instruction set is specified by an opcode, which is represented as a pattern of 1s and 0s. A compiler or interpreter translates code in a source language to machine code made up of those instructions.

    For example, take this code, where a variable, x, is assigned the value of 50:

    x = 50;
    

    The compiler might translate that to the following assembly language, where the AX register (for the x variable) is set with the value, 50 (in hexidecimal), using the MOV instruction:

    mov ax, 0x32
    

    If the opcode for MOV was 0xA0 and the code for the AX register was 0xB then the machine code, in binary, would look like this:

    10100000 00001011 00110010