Explanation

In terms of matrices, the algorithm can be written somewhat more succinctly. The idea is that at each step the values of the variables are such that the matrix

M =  
xy
uv

applied to the column vector (a,b)T (the input values) gives the updated values of a and b, say a' and b'. When b' = 0, we have a' = gcd(a,b), so (a',b')T = M(a,b)T gives gcd(a',b') = xa + yb in the first row and 0 = ua + vb in the second.