Convert IA32 assembly to C code

I am having difficulty translating the IA32 build code back to its C code. I am 99% of the way, but byte offsets and register storage are confusing.

The assembly code,, seems to movl %edx, %eaxset the value stored in %eaxequal to the value in %edx, but does that mean sub = result?

I am new to this, so your guidance is appreciated!

int d(int x, int y, int z)     // x at %ebp+8, y at %ebp+12, z at %ebp+16
{
    int sub, result;

    sub = z - y;               // movl 12(%ebp), %edx
    result = sub;              // subl 16(%ebp), %edx

    ???????????                // movl %edx, %eax

    result <<= 31;             // sall $31, %eax
    result >>= 31;             // sarl $31, %eax

    result = sub * result;     // imull 8(%ebp), %edx

    sub ^= x;                  // xorl %edx, %eax

    return result;
}
+4
source share
1 answer

The first two lines of asm are actually the first line of C, but are accessed and executed in two parts:

sub = y;                   // movl 12(%ebp), %edx
sub -= z;                  // subl 16(%ebp), %edx

, , , & t ( ) . , movl %edx, %eax result = sub, . , imull 8(%ebp), %edx edx, sub = x * result ( eax ). , xorl %edx, %eax, , result ^= sub. x, 8(%ebp), .

+3

Source: https://habr.com/ru/post/1668893/


All Articles