;;; exports global gcd ;;; imports extern getnum extern putnum extern usage section .text ;;; gcd --> expects arguments in rbx and rcx; returns answer in rbx gcd: push rax ; save the registers we are modifying and aren't used for push rcx ; for a return value push rdx ;;; compare rbx to rcx cmp rbx,rcx ;;; check to see if these are equal je finish ;;; check to see if rbx > rcx jg again ;;; if not, swap rbx and rcx so that rbx > rcx xchg rbx,rcx again: ;; shuffle rbx and rcx up to rax and rbx mov rax,rbx mov rbx,rcx ;; zero out rdx in preparation for division rdx:rax by rcx xor rdx,rdx ;; divide by rcx, remainder is in rdx div rcx cmp rdx,0 je finish mov rbx,rcx mov rcx,rdx jmp again finish: pop rdx pop rcx pop rax ret