Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Do You

Name: Anonymous 2009-05-06 16:28

Do you guys know how to write this C++ code into assembly language?

<code>
int GCD(int x, int y)
{
  x = abs(x);       //absolute value
  y = abs(y);
  do {
    int  n = x % y;
  x = y;
  y = n;
  } while (y > 0);
  return x;
}
</code>

Name: Anonymous 2009-05-06 18:31


gcd:
    oldEbp = 0
    retAddr = oldEbp + 4
    x = retAddr + 4
    y = x + 4

    pushl %ebp
    movl %esp, %ebp

    movl x(%ebp), %eax
    movl y(%ebp), %ebx

    cmpl $0, %eax
    jl negX
    jmp endNegX

negX:
    negl %eax
endNegX:

    cmpl $0, %ebx
    jl negY
    jmp endNegY

negY:
    negl %ebx
endNegY:

Loop:
    xorl %edx, %edx
    idivl %ebx
    movl %ebx, %eax
    movl %edx, %ebx
CheckLoop:
    cmpl $0, %ebx
    jne Loop

    movl %ebp, %esp
    popl %ebp
    ret


>>6
Cheater, here's some HAND-CRAFTED x86 assembly code.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List