;;; Authors: MCS-178 gang -- 02/10/2006 ;;; ;;; gcd.s -- find the gcd of two nonnegative integers a and b ;;; ;;; Registers Used: ;;; a -- input, output ;;; b -- input ;;; both a and b may be clobbered allocate-registers a, b ; inputs allocate-registers aremb ; temporary allocate-registers loop, bis0 ; labels read a read b Lloop: li bis0, Lbis0 jeqz b, bis0 rem aremb, a, b li a, 0 add a, a, b li b, 0 add b, b, aremb li loop, Lloop j loop Lbis0: write a halt