문제

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)
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top