We know machine level code are in form of 0,1 (binary). Now, in c programming using gcc for a program if cmd is –
gcc -c ok.c
where ok.c is a simple program to print “hi” in c.
Now, a file ok.o is created which is supposed to be machine level instructions.The content of ok.o file is something like-
^@^L^@UH��H�=^@^@^@^@�^@^@^@^@�^@^@^@^@�]�hi^@^@GCC: (Debian 9.3.0-10) 9.3.0^@^@^@^@^@^@^@^@^T^@^@^@^@^@^@^@^AzR^@^Ax^P^A^[^L^G^H�^A^@^@^^@^@^@^^@^@^@^@^@^@^@^X^@^@^@^@A^N^P�^BC
^FS^L^G^H^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^D^@��^@^@^@^@^@^@^@^@^@^
and so on lots of character like this. what does this output mean and if this is machine level instruction then why it is not in form of binary digit(0,1) i.e 1000110111111010101….(something like that) and also how can i see binary kind of code ? Please , also correct me if I am wrong somewhere.
Thanks
2
Answers
You can do this to produce an assembly file (ok.s):
The ok.s file be human readable text file (like your .c file). It will be a listing of the machine instructions. This is how a human ‘views’ the machine code.
For more information about what those instructions mean see:
https://en.wikipedia.org/wiki/X86_assembly_language
When you view your binary .o file you are viewing it as text (where 8 (or more)) binary bits will be forming a human viewable character depending on their value, which is why it looks like a bunch of random characters.
Given a simple C program like
if you want to look at actual machine code (not just the assembler, but the actual opcodes and operands), you have a couple of options:
Then use the
objdump
command with the-d
option (objdump -d simple
), and you’ll get a listing similar to this:-Wa,-aldh=listing-file
option to generate a listing of assembly and machine code:which will create a listing file similar to this:
If you build with the
-g
option, you’ll get the original source code interleaved with the generated output: