Assembly code vs Machine code vs Object code?

后端 未结 10 1932
执笔经年
执笔经年 2020-11-27 09:11

What is the difference between object code, machine code and assembly code?

Can you give a visual example of their difference?

相关标签:
10条回答
  • 2020-11-27 09:36

    Source code, Assembly code, Machine code, Object code, Byte code, Executable file and Library file.

    All these terms are often very confusing for most people for the fact that they think they are mutually exclusive. See the diagram to understand their relations. The description of each term is given below.



    Source code

    Instructions in human readable (programming) language


    High-level code

    Instructions written in a high level (programming) language
    e.g., C, C++ and Java programs


    Assembly code

    Instructions written in an assembly language (kind of low-level programming language). As the first step of the compilation process, high-level code is converted into this form. It is the assembly code which is then being converted into actual machine code. On most systems, these two steps are performed automatically as a part of the compilation process.
    e.g., program.asm


    Object code

    The product of a compilation process. It may be in the form of machine code or byte code.
    e.g., file.o


    Machine code

    Instructions in machine language.
    e.g., a.out


    Byte code

    Instruction in an intermediate form which can be executed by an interpreter such as JVM.
    e.g., Java class file


    Executable file

    The product of linking proccess. They are machine code which can be directly executed by the CPU.
    e.g., an .exe file.

    Note that in some contexts a file containing byte-code or scripting language instructions may also be considered executable.


    Library file

    Some code is compiled into this form for different reasons such as re-usability and later used by executable files.

    0 讨论(0)
  • 2020-11-27 09:37

    Assembly code is a human readable representation of machine code:

    mov eax, 77
    jmp anywhere
    

    Machine code is pure hexadecimal code:

    5F 3A E3 F1
    

    I assume you mean object code as in an object file. This is a variant of machine code, with a difference that the jumps are sort of parameterized such that a linker can fill them in.

    An assembler is used to convert assembly code into machine code (object code) A linker links several object (and library) files to generate an executable.

    I have once written an assembler program in pure hex (no assembler available) luckily this was way back on the good old (ancient) 6502. But I'm glad there are assemblers for the pentium opcodes.

    0 讨论(0)
  • 2020-11-27 09:37

    The source files of your programs are compiled into object files, and then the linker links those object files together, producing an executable file including your architecture's machine codes.

    Both object file and executable file involves architecture's machine code in the form of printable and non-printable characters when it's opened by a text editor.

    Nonetheless, the dichotomy between the files is that the object file(s) may contain unresolved external references (such as printf, for instance). So, it may need to be linked against other object files.. That is to say, the unresolved external references are needed to be resolved in order to get the decent runnable executable file by linking with other object files such as C/C++ runtime library's.

    0 讨论(0)
  • 2020-11-27 09:40

    I think these are the main differences

    • readability of the code
    • control over what is your code doing

    Readability can make the code improved or substituted 6 months after it was created with litte effort, on the other hand, if performance is critical you may want to use a low level language to target the specific hardware you will have in production, so to get faster execution.

    IMO today computers are fast enough to let a programmer gain fast execution with OOP.

    0 讨论(0)
提交回复
热议问题