I have an assembler program and I try to understand it. (I'm actually profiling it). Is there a Linux tool/editor that would structurize it a little for me? Displaying where loops/jumps are would be enough. Handy description of what an instruction does would be great.

- 328,167
- 45
- 605
- 847

- 48,526
- 41
- 139
- 208
-
You have the assembly source code, or are you using a disassembler on an executable? -- Do you know assembly? x86 (32-bit) processor? – mctylr Feb 24 '10 at 18:01
-
I have source dumped by oprofile. So I guess it is similar to objdump format. I have source as well but with heavy optimization oprofile (objdump?) can't find correspondence between ASM and C++ – Łukasz Lew Feb 24 '10 at 18:34
-
So you have the disassembly of an executable written in C++. This is sort of a different question than understanding a program originally written in assembly, because you want to make a connection between particular assembly instructions and the original C++ source. The first thing you can do, is ensure that the C++ compiler is run _with debugging enabled_, so extra debugging information is left in the executable for the disassembler to reference. Disassemblers only reverse the process back to assembly. There is also the process of decompiling. It tends to be harder and not very good results. – mctylr Feb 24 '10 at 21:23
6 Answers
If you look for something that resembles OllyDbg but for linux, you might try edb.

- 11,478
- 1
- 37
- 49
Since you are really reversing a high level language for profiling, you can do a couple things to help the process. First enable and preserve debugging information in the C++ compiler and linker (don't let it strip
the executable). In g++ the -g
command line flag does this. Second many C++ compilers have flags to output the immediate assembly source code, rather than emitting the object code (which is used by the linker). In g++ the -S
flag enables this.
The assembly from the compiler can be compared to the assembly from the oprofile disassembly.
I'm not very familiar with decompilers, but two including one from another SO post are Boomerang and REC for C, rather than C++.
I hope that helps.
Only, for PowerPC CPU The project Demono purpose to restore algorithms of binary code (currently, only for PPC) - and it's not fully decompiler. Project is under construction, but some examples are works. Site has Online service for generating C-like description of functions from assebler: online service for decompile PPC asm
For use it, you should perform following steps:
- Disassemble binary code(for PowerPC) to text of assembler (by IDA)
- Insert text of assebler to field "Ассемблер"
- Press button "Восстановить"
- Look to form "Восстановленный алгоритм"
For example, if your assembler has text:
funct(){
0x00000002: cmpw r3, r4
0x00000003: ble label_1
0x00000004: mr r6, r3
0x00000005: b label_2
0x00000006: label_1:
0x00000007: mr r6, r4
0x00000008: label_2:
0x00000009: cmpw r6, r5
0x0000000A: ble label_3
0x0000000B: mr r7, r6
0x0000000C: b label_4
0x0000000D: label_3:
0x0000000E: mr r7, r5
0x0000000F: label_4:
0x00000010: mr r3, r7
0x00000011: blr
}
Online service restore following function's algorithm description:
funct(arg_w_0, arg_w_1, arg_w_2){
if(arg_w_0>arg_w_1?true?false){
arg_w_0=arg_w_1;
}else{
}
if(arg_w_0>arg_w_2?true?false){
arg_w_0=arg_w_2;
}else{
}
return (arg_w_0);
}
And, therefore, funct() derive max of three numbers - max3().
Possible, this service helps you understand how assembler instructions works..

- 369
- 3
- 4
There's an Asm plugin for Eclipse you could use.
However, usually IDEs aren't employed for assembly programming. I'm not sure how much more understanding you will gain by easily spotting where the jumps and loops are - you have to read through everything anyway.

- 263,248
- 89
- 350
- 412
Not really, but you can always look at instruction references, use syntax highlighting (vim asm syntax) also you could step it through debugger if there's no limitation running it. For already assembled code this might be interesting: LIDA