m equ 3575 n equ 2925 m_local equ 6 ; stack offset from SP for m n_local equ 4 ; stack offset from SP for n org $1000 gcd ds.w 1 org $1500 lds #$1500 ; set up stack pointer ldd #m ; push m in stack pshd ldd #n ; push n in stack pshd jsr find_gcd std gcd leas 4,sp ; deallocate space used by parameters swi find_gcd pshx ; ************************************************************************************************************ ; The following subroutine uses the iterative division method to compute the gcd of two 16-bit ; integers and return the result in D. ; ************************************************************************************************************ gcd_loop ldd n_local,sp ; compute p = n % m ldx m_local,sp ; " idiv ; " cpd #0 beq done movw m_local,sp,n_local,sp std m_local,sp bra gcd_loop done ldd m_local,sp ; retrieve gcd pulx ; restore X rts end