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?
Reading disassembled code
Asked Answered
I might be wrong but the bigger output should be a consequence to the fact the disassembly contains more info like the address of each instruction. –
Marigraph
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.
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. –
Marigraph
You see I have a task to disaseble a example .exe and then run run it with the output code –
Trisomic
Didn't mean to suggest there was any optimization occurring. I updated the answer to address terminology pedantry. –
Radiocarbon
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). –
Marigraph
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. –
Radiocarbon
@nadirs Use the "Ask Question" button or post an answer of your own. The comment space is not for arguments. –
Radiocarbon
ok, here it is. Thanks for the heads-up. –
Marigraph
let us continue this discussion in chat –
Marigraph
I am not sure of the Assemblers you all use, but any code I write in MASM or FASM is exactly what I see when I run it though Olly. @OP are you using the MASM Macros to write your hello world? If so all those macros expand to code you don't see hence more code when you disassemble –
Unison
This is correct in the general case (e.g., Superoptimization and Object code optimizers), but it is unclear if this is what the user encountered. Gunner's explanation is probably more reasonable, but the asker has not really provided enough information. –
Goraud
© 2022 - 2024 — McMap. All rights reserved.