;; The first few lines were added after class. allocate-registers sp, one, oneDigit, multiDigitCase allocate-registers ten, n, cont, lastDigit, writeDigits li one, 1 li writeDigits, writeDigitsLabel li sp, 0 ;; Now we move to a portion written in class. li multiDigitCase, multiDigitCaseLabel li ten, 10 read n li cont, afterTopLevel writeDigitsLabel: slt oneDigit, n, ten jeqz oneDigit, multiDigitCase write n j cont afterTopLevel: halt multiDigitCaseLabel: rem lastDigit, n, ten ;; Everything after this point was added after class. st lastDigit, sp ;; store what we'll need later add sp, sp, one st cont, sp add sp, sp, one quo n, n, ten ;; subproblem: write all but the last digit li cont, afterRecursion j writeDigits afterRecursion: sub sp, sp, one ;; load back the stored values ld cont, sp sub sp, sp, one ld lastDigit, sp write lastDigit j cont