I wrote my c program add.c, then preprocessed with cpp, then compiled with CC to obtain an add.s file. Now I would like to open it to see the assembly code. Can't find a way to do it.
Asked
Active
Viewed 4,906 times
-3
-
4they're normal text files, so use your favorite editor, like vim or geany etc. – Tommylee2k Nov 17 '16 at 10:46
2 Answers
3
The .s
files are basically assembler source files, so you can pretty much open them in whatever tool you used to create the .c
files in the first place.
In other words, mere mortals will opt for Notepad++
or Emacs
, but the true intelligentsia will use Vim
:-)

paxdiablo
- 854,327
- 234
- 1,573
- 1,953
-
-
Yeah thank you you're right, the problem was that it told me that I couldn't, because there must have happened something wrong during compilation. I treid to use cc, typing on terminal cc add.c -o add.s but it doesn't work. – Gabriele Scarlatti Nov 17 '16 at 11:22
-
2@Gabriele, `cc add.c -o add.s` will almost certainly still create an executable file, it will just *call* it `add.s`. In other words, it won't be a text file assembler listing at all. You need to figure out what command line option tells your compiler to create the `.s` file rather than an executable. For example, `gcc -S add.c` will produce `add.s` for you (without needing to specify the actual output file explicitly) - it's the `-S` that does that for you. – paxdiablo Nov 17 '16 at 11:35
-
@paxdiablo Hi thank you for explaining to me. I'm a newbie and still don't get why i can generate an executable and call it add.s. Isn't ".s" the extension anymore, is it just part of the name of the file? – Gabriele Scarlatti Nov 17 '16 at 12:14
-
@Gabriele, you can usually *call* a file whatever you want (within the constraints of the file system). Consider, for example, renaming a file such as with `ren something.txt something_else.exe`. That text file doesn't magically become something you can execute just because you changed its name. That's especially so in UNIX-like systems (as opposed to Windows) since the extension is far less important there - it's more convention than something required. – paxdiablo Nov 17 '16 at 12:52
-
@paxdiablo! Thank you very much! I believe to have understood! Great explanation! – Gabriele Scarlatti Nov 17 '16 at 16:11
0
For getting .s file. if you have main.cpp file , just complile with g++ -S main.cpp for getting main.s file.
Now you can open with vim main.s

Ramanand Yadav
- 309
- 3
- 3