I know object code is the code after the compilation phase which is present in a object file(eg:aaa.obj). What is this file? Contains Machine Instructions? If so why can't I see any 0's and 1's in that file. Please help me out.
-
1Depends what you used to view the file. Any file will contain 0s and 1s. The Object file does contain machine instructions and other things that the linker uses to construct an executable. – Ayman Aug 31 '15 at 04:51
-
So,What should i use to view the file? – prog481 Aug 31 '15 at 04:52
-
Thanks a lot... Can you give me the name of a disassembler? – prog481 Aug 31 '15 at 04:58
-
depends what assembler you used, and what machine. Most assemblers can also disassemble object files. – Ayman Aug 31 '15 at 05:03
-
For Linux, `objdump` should work. – cadaniluk Aug 31 '15 at 06:10
-
what about for windows? – prog481 Aug 31 '15 at 06:16
-
On Windows use `dumpbin` with the `/disasm` option – Michael Petch Aug 31 '15 at 12:59
1 Answers
An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)
A linker takes all these object files and combines them to form one executable (assuming that it can, ie: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)
If so why can't I see any 0's and 1's in that file.
You are confusing object file concept with executable file concept. The thing is that object file contains compiled code and instructions for the linker (program building one executable file from one or more object files). The output of the linker program is actually executable file which contains expected by you zeros and ones.

- 1
- 1

- 1,613
- 14
- 20
-
even executable files don't show up 0's and 1's, instead some non-understandable scripts.Why? – prog481 Sep 02 '15 at 09:29
-
Yes, your computer works with 0 and 1's (the bits) but in reality it uses sequence of that. 8bit is one byte, and most systems use 8bytes at a time (a 64 bit system). As most people prefer text, and 8bits will do for western text (ascii), most editors try to show everything as ascii text. You will see many characters, as most of the 256 combinations in a byte are used for a char. But unless the file is text, you will see no (hardly) real words. To see details, you need a special program, like hexdump, od, etc. most Unix system have them, on windows it is sparse. – Albert Sep 02 '15 at 21:17