Mix Program in Assembly and C++ to Find Factorial of Number
This C++ program calculates the factorial of a number between 0 and 8 using inline 8086 assembly instructions. The multiplication is handled within an assembly loop, showcasing a basic yet insightful use of mul, dec, and jnz instructions. #include<iostream.h> #include<conio.h> void main() { clrscr(); short a; unsigned int c; cout << "\n Enter Number between 0 to 8:"; cin >> a; asm mov ax, 0000h asm mov al, 01h // Initialize AX to 1 asm mov cx, 0000h asm mov cx, a // Set CX loop counter to input value bac: asm mul cx // Multiply AX by CX asm dec cx // Decrement CX asm jnz bac // Loop until CX reaches zero asm mov c, ax // Move result from AX to variable c cout << "\n Factorial of " << a << " is " << c; getch(); }