What is the difference between object code, machine code and assembly code?
Can you give a visual example of their difference?
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.
Instructions in human readable (programming) language
Instructions written in a high level (programming) language
e.g., C, C++ and Java programs
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
The product of a compilation process. It may be in the form of machine code or byte code.
e.g., file.o
Instructions in machine language.
e.g., a.out
Instruction in an intermediate form which can be executed by an interpreter such as JVM.
e.g., Java class 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.
Some code is compiled into this form for different reasons such as re-usability and later used by executable files.
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.
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.
I think these are the main differences
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.