1. For the beginners and even for myself, I follow what the Albert Einstein has said:
"The wise man starts from the basic (simple and elementary) and then gradually moves to the complex one."
2. How is it to study the following 8086 based ASM program (I created in 1996) and C based Program in the computation of 5! (factorial of 5) for comparison?
**8086 Assembly Program to compute 5!** Use MicroTalk-8086 trainer (Fig-1) and demonstrate a Recursive Procedure by calculating the factorial of a number (up to 5 decimal). The result of the factorial will be in hex. The value will be displayed at positions D2D1 positions of the trainer. The remaining digit positions of the display would remain blank. Your task is to draw ASM codes, Flow Chart and Stack diagram.
; Data Value
(00475) (0074h) = xxxx (upto 0005) is to be entered first by the user
;Execution starts
ML1:01600 - BC FE FF : mov sp, 0FFFEh ; stcak top
01603 β BB 00 04 : mov bx, 0400h ; bx is a pointer
01606 β 90 90 90 : nops
ML2:01609 β 81 EC 04 00 : sub sp, 0004h ; keeping four RAM locations to hold X!
0160F β 8B 47 74 : mov ax, [bx+74h] ; number is loaded into ax-register
ML3:01612 β 50 : push ax ; 1st factor is saved onto stack
ML4:01613 β 9A 66 16 00 00 : call FACTO(01666h) ; get next factor if there is any
ML5:01618 -; the factorial of the contents of memory locations (00475)(00474) is at
; memory locations (0FFFD β 0FFFA). Get the results from these locations and
; display it at D4D-D1 positions of the MicroTalk-8086 trainer. D9-D5
; positions will remain blank.
01618 - BB 00 04 : mov bx, 0400h
0161B β BD FA FF : mov bp, 0FFFAh
0161E β 90 : nop
0161F β 90 : nop
01620 β 8B 46 00 : mov ax, [bp+00h] ; get x! from (0FFFB, 0FFFA)
01623 β 89 47 4E : mov WORD PTR [bx+4Eh], ax ; put into T3 of reserved RAM
01626 β 8B 46 02 : mov ax, [bp+02h] ; get X! from (0FFFD, 0FFFC)
01629 β 89 47 4F : mov WORD PTR [bx+4Fh], ax ;
0162C β 9A 7C F4 00 F0 : call SUR8 (0F47c) ; convert packed hex to cc-code
01631 β C7 47 44 00 00 : mov WORD PTR [bx+44h], 0000h ; blank D4D3 display
01636 β C7 47 46 00 00 : mov WORD PTR [bx+46h], 0000h ; blank D6D6 display
0163B β C7 47 48 00 00 : mov WORD PTR [bx+48h], 0000h ; blank D8D7 display
01640 β C7 47 4A 00 00 : mov WORD PTR [bx+4Ah], 0000h ; blank D9 display
01645 β 9A B6 FF 00 00 : call SUR3 (0FFB6h) ; transfer cc-code to display
ML6:0164A β EA 4A 16 00 00 : jmp ML6 (0164A) ; done, loop here
;FACTO Subroutibe
SR1:01660 β 8B EC : mov bp, sp ; user canβt use sp as a pointer
01662 β 8B 46 04 : mov ax, [bp+04h] ; get the number x passed from MLP
SR2:01665 β 3D 01 00 : cmp ax, 0001h ; check if x = 1
SR3:01668 β 75 0F : jne DETER (01679) ; if x>1, determine (x-1)
SR4:0166A β C7 46 06 01 00 : mov [bp+06h], 00001h ; x = 1, so, save x! = 1
0166F β C7 46 08 00 00 : mov [bp+08h], 0000h ;
SR5:01674 β EA 96 16 00 F0 : jmp EXIT (01696) ; factorial process is end
; DETER Subroutine
SR6:01679 β 81 EC 04 00 : sub sp, 0004h ;
0167D β 48 ; dec ax
SR7:0167E β 50 : push ax
SR8:0167F β 9A 60 16 00 00 : call FACTO ; recursive call
SR9:016684 β 8B EC : mov bp, sp
SR10:01686 β 8B 46 02 : mov ax, [bp+02h]
SR11:01689 β F7 66 0A : mul WORD PTR [bp+0Ah] ; 16-bit multiply,
SR12:0168C β 89 46 0C : mov [bp+0Ch], ax
0168F β 89 46 0E : mov [bp+0Eh]
SR13: 01692 β 81 C4 06 00 : add sp, 0006h
SR14: 01696 β CB ; ret
Stack Diagram/Data Structure for the above Recursive ASM program
//===================================================================
C Program to compute 5!
factr(n)
{
if (n ==1)
factorial = 1;
else
factorial = n*factr(n-1);
}
In fact, for n=5, n! = 5x4x3x2x1. In the above c-codes, we observe that the program works in the following ways:
(1) Get n =5 and save (K5 = 5 and saved in locations 0FFF8, 0FFF9)
(2) Get (n-1) = 4and save K4 = 4
(3) Get ((n-1)-)) = 3 and save K3=3
(4) Get n-3 = 2 and save K2=2
(5) Get n-4 =1 and save K1 =1
(6) Now the statement:
if (n==1)
Factorial =1
Is executed and save 1! =00001h at locations 0FFD2h β 0FFD5h
(7) The stack structure is arranged in such a way so that the same program codes could be repetitively used to get the result:
1h x 2h = 2h x3h = 6hx4h = 18hx5h = 78h = 120
Flow Chart for the Recursive Codes of the above C-Routine to compute 5!

MicroTalk-8086 Trainer
Figure-1: