Write an assembly (Assembly x86) program to calculate the factorial of an unsign
ID: 3708455 • Letter: W
Question
Write an assembly (Assembly x86) program to calculate the factorial of an unsigned integer n (n!)
- You need to prompt the user to enter an unsigned integer:
Enter an unsigned integer (n!):
- Pass the entered number to the Factorial subroutine.
- The calculated n! needs to be displayed on console screen from the main subroutine.
- See the book page 305-306 where you will find main and factorial subroutines.
- Make the required changes and run the program. - Run your program using the debugger to verify your answers.
? Use Step Into instead of Step Over to keep track of the stack, ESP, EBP, EIP during debugging.
- To access the stack memory, copy the value of ESP from the register window and past it in the search text box in the memory window.
What will happen to the Factorial program’s output when you try to calculate 13! and why?
How many bytes of stack space will be used by the Factorial subroutine when calculating 3!?
Explanation / Answer
;program to find the factorial of a number INCLUDE io.h Cr EQU 0ah Lf EQU 0dh data SEGMENT p_n DB cr, lf, 'Enter n: ',0 p_res DB cr, lf, 'The factorial is: ',0 tmpstr DW 40 DUP (?) data ENDS code SEGMENT ASSUME cs:code, ds:data start: mov ax, data mov ds, ax ;input n1 output p_n inputs tmpstr, 10 atoi tmpstr ;initialize mov bx, ax mov ax, 01h ;factorial iterations n_ip: imul bx dec bx jnz n_ip ;output factorial output p_res itoa tmpstr, ax output tmpstr quit: mov al, 00h mov ah, 4ch int 21h code ENDS END start
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.