Identifying address calculation insns in asm
I am looking at x86 asm and I wanna try to read it and identify a bug in my cpp code and OPTIMIZE. But the asm has a lot of overhead from address calculating instructions. And I can't seem to find a way to identify the ones that are calculating an address from the ones that are doing other tasks. for example an add could be used to both calculate a mem address to be used in later insn or to do a regular addition operation that is available in my code.
is there a way to do it eas开发者_开发问答ily, like do they used fixed registers for address calculation? or do I have to trace the code from beginning to end?
EDIT: it seems there is no clear way to identify them. But is it fair to assume that only mov, add, sub and lea are address calculating instructions? or does x86 have anything more complex?
thanks
No, not really. Most registers are general purpose, and used for all kinds of calculations. Some compilers are even smart enough to use address calculating instructions like LEA to compute other things.
You will probably have to find where a variable is loaded into a register, and follow it from there.
You can trace the code from end to beginning. For example, there are instructions that read or write registers to memory (e.g. mov eax, [ebx]
using Microsoft syntax). When you see such an instruction, you can identify which register is used as an address (ebx
in my example), then go back in the code and see how the register is calculated.
Beware of the "jump" instructions - if your code has much conditional execution, it might be hard to "go back in code", and it might be easier to just "trace the code from beginning to end".
精彩评论