Is the disassembly listing generated by a disassembler exactly the same as the assembly code listing that is optionally generated by a compiler during the compilation of C code?
-
1Your question is unclear. What do you mean by "the assembly code generated by a compiler's assembler"? First off, I don't think any modern compiler still generates assembler at all, at least not by default. And secondly, the assembler doesn't generate assembly code, it reads assembly code and generates object code.– Jörg W MittagFeb 19, 2017 at 2:58
-
1I assume the OP refers to the optional assembly-language listing file which a compiler can output.– ChrisWFeb 19, 2017 at 3:46
-
1is your disassembler operating on raw machine code from an executable? or is it disassembling an object code file (that is input to the linker) that comes from compiling or assembling source code? for the former, all labels and symbols are lost and the disassembler has to make them up. for the latter, it is possible that the object files have all of the original symbols. but in either case, all of the comments and formatting style is gone.– robert bristow-johnsonFeb 19, 2017 at 7:50
-
@JörgWMittag Let me put the question in a different way - what is the difference between assembly code (such as those in .s, .asm, etc) and assembly listing (.lst)?– gauthamMar 4, 2017 at 2:05
-
@gautham: "Listing" is an old word for "printout", from back in the early days of computing, when there were no screens, and the only way to display code was to print it out ("list it") on paper. Ever since the invention of the computer screen, it means essentially the same thing as "code".– Jörg W MittagMar 4, 2017 at 7:24
2 Answers
No I'd expect that the compiler's assembly output can include symbolic names, of functions and of variables, even struct
member names. The disassembly would only contain numbers.
In other words, both the compiler and the disassembler can output opcode instruction names, but the disassembler merely outputs numbers instead of symbols when it refers to memory addresses. Or if it's disassembling a DLL, the disassembler might output the public symbols exported from the DLL; but (unlike the compiler) not the symbolic names of internal variables and subroutines.
Apart from that, it's the same machine code. There's also a linker, which happens after the compiler (the linker's processing will be evident in the numeric addresses shown by the disassembler).
It depends upon the compiler, and usually it might not be the same (e.g. because the compiler generates many local labels that get lost).
If you use GCC to compile your foo.c
source code (technically, a translation unit) I suggest to use
gcc -Wall -O -fverbose-asm -S foo.c
which produces the assembler code foo.s
that you can look into with some editor. Thanks to -fverbose-asm
that assembler file also contain useful generated comments (to help you understand what is going on).