; Z https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Pseudocode bezout: ; (old_r, r) := (a, b) # l1, l2 put 1 -> l3 ; (old_s, s) := (1, 0) # l3, l4 put 0 -> l4 put 0 -> l5 ; (old_t, t) := (0, 1) # l5, l6 put 1 -> l6 loop: jz l2, done ; while r ≠ 0 do sdiv l1, l2 -> l7 ; quotient := old_r div r # l7 copy l2 -> t1 ; (old_r, r) := (r, old_r − quotient × r) mul l2, l7 -> l2 sub l1, l2 -> l2 copy t1 -> l1 copy l4 -> t1 ; (old_s, s) := (s, old_s − quotient × s) mul l4, l7 -> l4 sub l3, l4 -> l4 copy t1 -> l3 copy l6 -> t1 ; (old_t, t) := (t, old_t − quotient × t) mul l6, l7 -> l6 sub l5, l6 -> l6 copy t1 -> l5 jmp loop done: copy l3 -> rv copy l5 -> l1 ret