x86 Assembly MASM Write an assembly program to calculate the factorial of an uns
ID: 3859899 • Letter: X
Question
x86 Assembly MASM
Write an assembly program to calculate the factorial of an unsigned integer n (n!) You need to prompt the user to enter an unsigned integer: Enter unsigned integer (n!): To do this, use WriteString and ReadDec Pass the entered number to the Factorial subroutine The calculated n! needs to be displayed on console screen from main subroutine See the book page 305-306 where you will find main and factorial subroutines. Make the required changes and run the program 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. Remember to have 0x (it tells debugger that the number is a hexadecimal number) in front of the pasted ESP value (0x4000407C). Submit the following: Lastname2.asmExplanation / Answer
DATA SEGMENT NUM DB ? FACT DB 1H RES DB 10 DUP ('$') MSG1 DB "ENTER NUMBER : $" MSG2 DB 10,13,"RESULT : $" DATA ENDS CODE SEGMENT ASSUME DS:DATA,CS:CODE START: MOV AX,DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H MOV AH,1 INT 21H SUB AL,30H MOV NUM,AL MOV AH,0 MOV AL,FACT MOV CH,0 MOV CL,NUM LABEL1: MUL CL LOOP LABEL1 LEA SI,RES CALL HEX2DEC LEA DX,MSG2 MOV AH,9 INT 21H LEA DX,RES MOV AH,9 INT 21H MOV AH,4CH INT 21H CODE ENDS HEX2DEC PROC NEAR MOV CX,0 MOV BX,10 LOOP1: MOV DX,0 DIV BX ADD DL,30H PUSH DX INC CX CMP AX,9 JG LOOP1 ADD AL,30H MOV [SI],AL LOOP2: POP AX INC SI MOV [SI],AL LOOP LOOP2 RET HEX2DEC ENDP END START
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.