Practice problems, do not submit for the lab report. The section for the lab report is at the end.
Procedures in SMS/x86 – continued. The FACTORIAL 1] Solve Task 25 from the SMS documentation:
Write a recursive procedure that works out Factorial N. Use the stack for parameter passing. Use this definition of Factorial:
Factorial ( 0 ) is defined as 1.
Factorial ( N ) is defined as N * Factorial (N - 1).
To calculate Factorial (N), the procedure first tests to see if N is zero and if not then re-uses itself to work out N * Factorial (N - 1).
Use this starter code:
; ----- Main program for recursive factorial ---------------- MOV AL,3 ; Do not try n>5, it overflows PUSH AL ; Parameter is passed on the stack CALL 60 POP AL ; Factorial is here OUT 01 ; Output the result to port 01 (traffic lights) HALT ; ----- Procedure for recursive factorial-------------------- ORG 60 ; Code starts at address  POP DL ; Return address POP AL ; Only parameter
MOV CL, 0 CMP AL, CL JNZ Recu
Base: MOV AL, 1 ; If n==0, n! is 1 PUSH AL PUSH DL RET