;; read in a non-negative integer n and write (n-1)! + (n-2)! allocate-registers n, cont, factorial, fact, zero, one, test, loop, first, second, result li factorial factorialL li zero 0 li one 1 li first firstL li second secondL li loop loopL read n sub n n one li cont firstL j factorial firstL:: add result fact zero sub n n one li cont secondL j factorial secondL: add result result fact write result halt ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; compute n! iteratively ;; n - input ;; fact - output ;; cont - return address ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; factorialL: li fact 1 loopL: sgt test n zero jeqz test cont mul fact fact n sub n n one j loop