I wrote simple Hello word program with masm32. But then when I try to disassemble it with IDA and I am getting much bigger output (I won't write it there because it would take to much space). And I don't get it why it's different. How to run the disasembled code?
1 Answer
This is normal. Compilation is a "lossy" process, which means that if you compile code and then decompile it, you're not guaranteed to get exactly the same thing out that you originally put in. The same thing applies to assembly language. When you assemble and link the code, it's a one-way process.
This is why programmers save the original source code, rather than just trying to decompile their binaries when they want to fix bugs.
10 Comments
Nadir Sampaoli
You don't compile assembly, you assemble and link it. Consider that for each opcode there's a corresponding binary value, so you don't have optimization typical of compiled (a.k.a. high level) languages.
LTnewbie
You see I have a task to disaseble a example .exe and then run run it with the output code
Cody Gray
Didn't mean to suggest there was any optimization occurring. I updated the answer to address terminology pedantry.
Nadir Sampaoli
Not to be annoying, but it's not just pedantry. Compiling and assembling are two rather different operations: a compiler modifies the structure of the code you write; instead, assembly has a 1:1 ratio to machine code (binary). It's a relevant difference, because when you disassemble ASM code you'll get exactly what you wrote (except for addresses and offset values, but their size doesn't change anyway).
Cody Gray
No, you don't. That's not guaranteed. It's more likely than with a compiler, sure, but you are not guaranteed to get the same thing from your disassembler that you passed to your assembler. That's the whole point. Not all assembly instructions are translated 1:1 to machine instructions.
|