I need to analyze assembly code...

Started by
19 comments, last by LorenzoGatti 11 years, 6 months ago
I must analyze some assembly code..

Is there some kind of "assembly code analyzer"?
Or do i need to learn assembly? sad.png
An invisible text.
Advertisement
Kinda need to learn it.. what is the code and what is the purpose of the analysis?
Depends when you mean by "analyze", if you mean find out what it does, then yes, you probably need to understand the code and the computer won't help you do that. If you mean how fast it'll be, how to optimize it, etc, then there are tools available for this kind of stuff (but it doesn't hurt to understand what the assembly is doing, either).

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

I need to know how conditional statements, loops and etc translate into assembly.
Where can I learn some assembly?
An invisible text.
If you just want to see how code in one language turns into assembly, most compilers give you an option to see generated assembly. For gcc you can use the -S switch and with MSVC you can use the /FA switch.
That part is not too hard. The first hit on Google for `assembly x86 tutorial' was this page, which seems reasonable. You can then ask your C or C++ compiler to generate assembly output for some simple programs and try to analyze what it's doing. If you have optimizations turned off, it should be pretty straight forward most of the time.

If you get far enough to understand how conditional statements and loops are implemented, you should make a little extra effort and understand how function calling and local variables work, since that's very informative for any programmer.

If you have optimizations turned off, it should be pretty straight forward most of the time.


Well, I must anaylze a code with full optimization especially in a loop, so I know what kind of loop optimization(such as interchanging, unrolling) is happening.
Is optimized assembly harder to understand?
An invisible text.
Start with unoptimized code until everything makes sense. Reading optimized code can be a bit of a challenge, and you should probably start with the easiest code you can get your hands on.
I found the following free e-book: Programming From the Ground-Up
I believe it will cover the intel syntax, which is easier to learn.
Try to find resources on the intel developer zone as well.

I like to use objdump + gcc on Linux to have the assembly code with the C code commented in between.

> gcc -g test.c -o test.o
> objdump -dS test.o > test.asm


On Windows, Visual Studio gives you assembly code pretty easily as well: right-click on your code and select "Show Dissasembly"
Programming is an art. Game programming is a masterpiece!

I like to use objdump + gcc on Linux to have the assembly code with the C code commented in between.
> gcc -g test.c -o test.o> objdump -dS test.o > test.asm
On Windows, Visual Studio gives you assembly code pretty easily as well: right-click on your code and select "Show Dissasembly"


I did

g++ -O3 main.cpp -o main.o
objdump -dS main.o >main.asm

but I don't get c++ code commented in between.
Instead I get assembly like below instead

(excerpt)
[source lang="plain"]main.o: file format pei-i386
main.o: file format pei-i386

Disassembly of section .text:

00401000 <___mingw_CRTStartup>:
401000: 53 push %ebx
401001: 83 ec 38 sub $0x38,%esp
401004: a1 70 40 40 00 mov 0x404070,%eax
401009: 85 c0 test %eax,%eax
40100b: 74 1c je 401029 <___mingw_CRTStartup+0x29>
40100d: c7 44 24 08 00 00 00 movl $0x0,0x8(%esp)
401014: 00
401015: c7 44 24 04 02 00 00 movl $0x2,0x4(%esp)[/source]

by the way "go to disassembly" works excellently in VC++
An invisible text.

This topic is closed to new replies.

Advertisement