Hi all,
Recently I've taken it upon myself to learn some assembly, to aid my software development skills and i've tried some basic code and taught myself some registers and Now i've succeeded in coding my first algorithm in assembly.(albeit an easy one). I've coded the subtraction based Euclidean algorithm
Code:
function gcd(a, b)
    if a = 0
       return b
    while b ≠ 0
        if a > b
           a := a − b
        else
           b := b − a
    return a
My assembly is a very literal translation, so Please give me some tips on how to optimize it.
This was written in Delphi 7 Inline Assembler (BASM)
Assembly Code:
  1. test ecx,ecx; // Check If Zero
  2.   jnz @@Continue;  //IF it is not Zero Go to @@Continue, Else go on
  3.   mov eax,edx;  //Put second paramater as result
  4.   ret;          //Return
  5. @@Continue:
  6.   test edx,edx; //Begin of while loop
  7.   jz @@Wend;   // If second paramater is zero go to the end
  8.   cmp ecx,eax;  // Compare First and second paramater
  9.   jnb @@Lower;  //If First > second then go to @@Lower
  10.   jmp @@Higher;  //Else go to higher
  11. @@Lower:
  12.   sub ecx,edx;  // first = first - second
  13.   jmp @@Continue; // next iteration of while loop
  14. @@Higher:
  15.   sub edx,ecx; // second = second - first
  16.   jmp @@Continue;// next iteration of while loop
  17. @@Wend: //While loop ended, need to return value.
  18.   mov eax,ecx;