I need to analyze assembly code...

Started by
19 comments, last by LorenzoGatti 11 years, 6 months ago
1 C++ line is not 1 assembly line, especially with optimizations enabled. There is no simple one-to-one translation between a lower level and a higher level language. You will just need to learn basic assembly, there is no way around that. You can't learn how to ride a bike by driving a car!

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

Advertisement
You can get the original code interleaved with the generated assembly with this command: g++ test.cpp -c -g -O3 -Wa,-ahl=test.lst

Give it a try!
Thanks, it works.

I was wondering if assembly code could show if branch prediction is taking place.
An invisible text.

I was wondering if assembly code could show if branch prediction is taking place.


No, that doesn't make any sense. Branch prediction is a feature of the CPU, which tries to execute the code as fast as possible, but the assembly is not instrumented in any way to enable it: The CPU will do it automatically everywhere.
Thanks to everyone who answered my question!

so much to know for a science fair project...
An invisible text.
The science fair project is so you learn a lot of things, not the other way around. :)

[quote name='lride' timestamp='1349576724' post='4987559']
I was wondering if assembly code could show if branch prediction is taking place.


No, that doesn't make any sense. Branch prediction is a feature of the CPU, which tries to execute the code as fast as possible, but the assembly is not instrumented in any way to enable it: The CPU will do it automatically everywhere.
[/quote]

Actually, this is not true for all instruction sets. Some don't have complex branch prediction mechanisms but rely on branch hinting where a special branch hint instruction has to be issued a few cycles before the branch. In those cases you can actually check in the assembly if the branch hint instruction is present and located in the right spot.

For x86 (or x86_64) however, this is not the case, as alvaro already pointed out. But all modern intel and amd CPUs have hardware counters that can be used by profilers to tell you, where branch mispredictions occure. See oProfile (Linux) or vTune and CodeAnalyst (Windows).
My two cents: grab a disassembler - a program which shows you the assembly of a compiled EXE or DLL file.. I used to modify all sorts of programs (while simultaneously gaining a bare-minimum awareness of assembly itself) by disassembling them, and editing their code directly using a hex editor - overwriting small bits of existing code by surmising the actual byte opcodes of the asm instructions I desired and writing them in by hand.. Also, writing programs that would do it all in memory (WriteProcessMemoryEx) so that the original file could be left alone while effecting the equivalent change in functionality once the target was running. That may or may not help you.
I know it's not the same architecture (6502 is not x86), but I just wanted to throw this out there: Machine Language for Beginners.

I need to know how conditional statements, loops and etc translate into assembly.
Where can I learn some assembly?


You should definitely read Code Optimization: Effective Memory Usage by well-known code-hacker Kris Kaspersky. One of the best books on the subject you want to know.

This topic is closed to new replies.

Advertisement