在x86汇编混淆添加命令 [英] Confusing add command in x86 assembly
问题描述
我一直在寻找通过一些code和发现2号线是困扰我:
I was looking through some code and found 2 lines that perplexed me:
add -0x4(%esi,%ebx,4),%eax
cmp %eax,(%esi,%ebx,4)
我习惯了标准的添加SRC,DST
和 CMP X1,X2
和我不是真的知道什么这些线路实际上做的。
I am accustomed to the standard add src,dst
and cmp x1,x2
and I'm not really sure what these lines are actually doing.
我相信这是使用GCC编译
I believe that it is compiled with GCC
推荐答案
这是一个使用基地+(索引*比例)+位移寻址模式。至少,我是这么认为的。我不是真正熟悉AT& T公司的语法。我认为,英特尔的语法是:
That's using the Base + (Index * Scale) + Displacement addressing mode. At least, I think so. I'm not real familiar with the AT&T syntax. I think the Intel syntax would be:
add eax,[esi + ebx*4 - 4]
cmp [esi + ebx*4],eax
这看起来像它的索引为整数(4字节的值)的数组。用C试想一下,你想从一些数组元素的值与总,是这样的:
This looks like it's indexing into an array of integers (4-byte values). Imagine in C that you want to add the value from some array element to a total, like this:
int a[100];
int i = 10;
int total = 0;
total += a[i-1];
现在,让 ESI
持有数组的地址, EBX
持有我
和 EAX
持有的价值33你会得到:
Now, make esi
hold the address of the array, ebx
hold the value of i
, and eax
hold the value 33. You'd get:
add eax,[esi + ebx*4 - 4]
的比较指令被测试,看看是否结果( eax中
)等于所述阵列中的下一个值。在C的例子,这将是等同于总
比较 A [I]
。
The comparison instruction is testing to see if the result (in eax
) is equal to the next value in the array. In the C example, that would be equivalent to comparing total
to a[i]
.
这篇关于在x86汇编混淆添加命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!