0

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?

  • 1
    Your 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 Mittag Feb 19 '17 at 2:58
  • I assume the OP refers to the optional assembly-language listing file which a compiler can output. – ChrisW Feb 19 '17 at 3:46
  • is 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-johnson Feb 19 '17 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)? – gautham Mar 4 '17 at 2:05
3

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).

0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.