• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to convert this code into assembly....

TurtleMan

Golden Member
In the process of try to find the GCD,

Had the following alog.

Gcd(int a, int b, int *result){

while(a!=b){

if(a > b)

a = a - b;

else

b = b - a;

}

*result = a;

}


I tried to put it in assembly, can someone check if im missing something ?




void lab1( int a, int b, int *result )
{
__asm
{
mov esi, result
//save the current status of the registers
push eax
push ebx
push edx

//put the variables into the registers
mov eax, a
mov ebx, b


START_WHILE:
cmp eax, ebx
je END_WHILE

cmp eax,ebx
jle Else_Block

sub eax, ebx
jmp START_WHILE

Else_Block:
sub ebx, eax
jmp START_WHILE

END_WHILE:
move edx



//put the answer to result
mov [esi][0], edx

//restore the original status of registers.
pop edx
pop ebx
pop eax
}
return;

}



Basically it is the bold part , am i missing something ?
Thanks a lot guys ,
 
Back
Top