x86 instruction meaning [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-11-28 14:11:44

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.

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.

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