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

Pages: 1-

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 16:28

Yes

Name: Anonymous 2009-05-06 16:40

Do tell please

Name: Anonymous 2009-05-06 16:57

But compilers do that, translate sepples into asm.

Name: Anonymous 2009-05-06 17:13

hmm..somethings not right. I'm getting errors.

Name: YEP HERE IT IS 2009-05-06 17:29

LCFI5:
        movl    12(%ebp), %ecx
        ; wat
        movl    %eax, %edx
        sarl    $31, %edx
        xorl    %edx, %eax
        movl    %edx, %esi
        subl    %eax, %esi
        ; wat
        movl    %ecx, %eax
        sarl    $31, %eax
        xorl    %eax, %ecx
        movl    %eax, %edi
        subl    %ecx, %edi
        jmp     L4
L8:
        movl    %edi, %esi
        movl    %ecx, %edi
L4:
        movl    %esi, %edx
        movl    %esi, %eax
        sarl    $31, %edx
        idivl   %edi
        testl   %edx, %edx
        movl    %edx, %ecx
        jg      L8
        movl    %edi, %eax
        popl    %esi
        popl    %edi
        leave
        ret

Name: Anonymous 2009-05-06 17:31

I don't.

Name: Anonymous 2009-05-06 17:35

How come I didn't get that...sigh

Name: Anonymous 2009-05-06 18:30

LEARN WHAT A COMPILER IS AND USE IT!

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.

Name: Anonymous 2009-05-07 6:55

No, John, you are the errors.

Name: Anonymous 2009-05-07 12:37

>>10
Once you start declaring variables in your ASM code, you do not really write assembly code, but fall into the endless pit of fail and AIDS. MLIHBT

Name: Anonymous 2010-12-17 1:39

Erika once told me that Xarn is a bad boyfriend

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