IN A
IN B
; this is equivalent to "jump to this line if a-b==0 <=> a==b". The original Euclidean algorithm does while(a != b).
MOV RES B
SUB RES A
JZ 21
CMP A B
; jump to this line if a>=b
JZ 15
; else we continue here. this is for b>a
SUB B A
; this basically just does RES:=0 because in our case C starts at 0 and A>=0 always. We do this because we don't have a normal jump function.
CMP A C
JZ 3
; this is for a>=b
SUB A B
; again just a regular jump
CMP A C
JZ 3

; this is where we jump when a==b
OUT A
RETURN