What is the difference between object code, machine code and assembly code?
Can you give a visual example of their difference?
What is the difference between object code, machine code and assembly code? Can you give a visual example of their difference? |
|||||||||||||
|
Machine code is binary (1's and 0's) code that can be executed directly by the cpu. If you were to open a "machine code" file in a text editor you would see garbage, including unprintable characters (no, not those unprintable characters ;). Object code is a portion of machine code that hasn't yet been linked into a complete program. It's the machine code for one particular library or module that will make up the completed product. It may also contain placeholders or offsets not found in the machine code of a completed program that the linker will use to connect everything together. Assembly code is plain-text and (somewhat) human read-able source code that has a mostly direct 1:1 analog with machine instructions. This is accomplished using mnemonics for the actual instructions/registers/other resources. Examples include things like |
|||||||||||||||||||||
|
The other answers gave a good description of the difference, but you asked for a visual also. Here is a diagram showing they journey from C code to an executable. |
|||||||||||||||||||||
|
Assembly code is a human readable representation of machine code:
Machine code is pure hexadecimal code:
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. |
|||||||||||||||||||||
|
|
|||
|
One point not yet mentioned is that there are a few different types of assembly code. In the most basic form, all numbers used in instructions must be specified as constants. For example: $1902: BD 37 14 : LDA $1437,X $1905: 85 03 : STA $03 $1907: 85 09 : STA $09 $1909: CA : DEX $190A: 10 : BPL $1902 The above bit of code, if stored at address $1900 in an Atari 2600 cartridge, will display a number of lines in different colors fetched from a table which starts at address $1437. On some tools, typing in an address, along with the rightmost part of the line above, would store to memory the values shown in the middle column, and start the next line with the following address. Typing code in that form was much more convenient than typing in hex, but one had to know the precise addresses of everything. Most assemblers allow one to use symbolic addresses. The above code would be written more like: rainbow_lp: lda ColorTbl,x sta WSYNC sta COLUBK dex bpl rainbow_lp The assembler would automatically adjust the LDA instruction so it would refer to whatever address was mapped to the label ColorTbl. Using this style of assembler makes it much easier to write and edit code than would be possible if one had to hand-key and hand-maintain all addresses. |
|||||||||||||
|
Assembly code is discussed here. "An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture." Machine code is discussed here. "Machine code or machine language is a system of instructions and data executed directly by a computer's central processing unit." Basically, assembler code is the language and it is translated to object code (the native code that the CPU runs) by an assembler (analogous to a compiler). |
|||
|
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. |
|||
|
Assembly is short descriptive terms humans can understand that can be directly translated into the machine code that a CPU actually uses. While somewhat understandable by humans, Assembler is still low level. It takes a lot of code to do anything useful. So instead we use higher level languages such as C, BASIC, FORTAN (OK I know I've dated myself). When compiled these produce object code. Early languages had machine language as their object code. Many languages today such a JAVA and C# usually compile into a bytecode that is not machine code, but one that easily be interpreted at run time to produce machine code. |
|||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?