x86 instruction meaning [duplicate]

风流意气都作罢 提交于 2019-12-17 20:56:21

问题


I'm running through some code right now on gdb and I have no clue what these two instructions actually do. If anyone could help me out, I'd really appreciate it.

add  -0x2c(%ebp, %ebx, 4), %eax
cmp  %eax, -0x28(%ebp, %ebx, 4)

回答1:


x86 assembly is usually much easier to understand when you write it in Intel syntax instead of AT&T syntax.

In Intel syntax it would be:

add eax,[ebp+4*ebx-0x2C]
cmp [ebp+4*ebx-0x28],eax

The first instruction (add) adds the value of word stored in the memory address [ebp+4*ebx-0x2C] to the value of eax, and stores the sum in eax.

The second instruction (cmp) compares eax with [ebp+4*ebx-0x28] by subtracting the value of eax from the value of the word stored in the memory address [ebp+4*ebx-0x28], and sets flags (OF, SF, ZF, AF, PF, CF) accordingly but does not save the result anywhere. cmp is exactly the same as sub, the only difference being the fact that in sub the result is saved, in cmp not.

The type of comparison is usually created in the form a conditional jump. In x86 assembly there are a lot of conditional jumps and whether they branch depends on the values of the flags.




回答2:


That's AT&T assembly syntax. Those addressing modes are a bit weird looking, but in pseudocode, they mean:

eax = *(ebp + ebx*4 - 0x2c)

and

compare eax to *(ebp + ebx*4 - 0x28)

Here's a link with complete explanation.



来源:https://stackoverflow.com/questions/12327408/x86-instruction-meaning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!