FACTORIAL: MOV R1, -(R6)  ; back up
           MOV 4(R6), R1  ; x
           DEC R1  ; x-1
           BLE BOTTOM  ; if x<=1, bottom out from recursion
           MOV R1, -(R6)  ; push recursive argument
           JSR R7, FACTORIAL
           ADD #2, R6  ; pop
           ; that gives us f(x-1); now compute x*f(x-1)
           MOV R0, R1
           MUL 4(R6), R1
           MOV R1, R0
           BR RETURN
   BOTTOM: MOV #1, R0
   RETURN: MOV (R6)+, R1  ; restore
           RTS R7


[exam] [CSC 258 additional problems] [main course page]