_TEXT SEGMENT a$ = 48 b$ = 56 gcd PROC ; 5 : U64 gcd( U64 a, U64 b ) { ; a in rcx, b in rdx $LN5: sub rsp, 40 ; reserve some stack space mov r8, rdx ; put a copy of b in r8 ; 6 : return !b ? a : gcd( b, a % b ); mov rax, rcx ; put a in rax (result register) test rdx, rdx ; test b je SHORT $LN4@gcd ; jump to return if it is 0; ie. if b=0 return a xor edx, edx ; empty rdx ready for div mov rcx, r8 ; move b into rcx ( ie. b becomes a for recursive call ) div r8 ; divide rdx:rax (0:a) by r8 (b); leaves quotient in rax, the remainder (modulus) in rdx (thus b in the recursive call) call gcd ; recurse $LN4@gcd: ; result is in rax. ; 7 : } add rsp, 40 ; clean up the stack ret 0 ; return popping 0 bytes from the stack gcd ENDP _TEXT ENDS