GCD in x86 asm
A small gcd implementation in asm (NASM syntax). It uses Euklid's algorithm, and is around 4 times faster than the same algorithm in C. Maybe it could be done even faster with the modulo version of the algorithm, but division/modulo tends to be slow.
global asm_gcd ; uint32_t asm_gcd(uint32_t a, uint32_t b) asm_gcd: push ebp mov ebp, esp mov eax, [ebp+8] ; eax = a mov edx, [ebp+12] .loop: cmp eax, edx jle .eloop xchg eax, edx .eloop: sub edx, eax test eax, eax jnz .loop .end: xchg eax, edx leave ret

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here
Comments: