Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why disassemble when the source code is available?

Why not instruct the compiler to stop after code generating assembly from C?

Sorry for the stupid questions.



Why disassemble when the source code is available?

Because there isn't a one-to-one relationship between the original source and the compiled code. Optimizing C compilers (meaning all modern C compilers) frequently go so far as to substitute completely different algorithms for code sequences that they recognize. The source code tells you the intended behavior, the assembly tells you what's actually happening.

Why not instruct the compiler to stop after code generating assembly from C?

You are right that you could get the most of the same information by looking at the generated assembly (-S with gcc/icc/clang). There usually isn't a lot of savings in time, though, as assembling is a fast operation.

Also, the compiler generated assembly is often messy, and cluttered with machine generated comments. Disassembled code is in a standard format, and can be easier to read. The disassembly also tells you alignment and instruction length, which can occasionally be essential.


What about using inline assembly for the switch?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: