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 ,
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 ,