;; Read in two integers a, b and print out their gcd, ;; like in the following python script: ;; ;; a = input() ;; b = input() ;; print gcd(a, b) ;; ;; def gcd(a, b): ;; if a < 0: a = -a ;; if b < 0: b = -b ;; while b > 0: ;; a, b = b, a % b ;; return a allocate-registers a ; input, output allocate-registers b ; input allocate-registers cont ; continuation register allocate-registers gcd, testb, loop ; labels allocate-registers zero ; constant allocate-registers newb, test ; temporary li zero 0 li testb Ltestb li gcd Lgcd li loop Lloop li cont Ldone read a read b j gcd Ldone: write a halt ;;;;;;;;;; gcd starts here Lgcd: slt test a zero jeqz test testb sub a zero a Ltestb: slt test b zero jeqz test loop sub b zero b Lloop: jeqz b cont rem newb a b add a b zero add b newb zero j loop