Intel x86 Assembly 1. ( 9 points) Write an assembly program to calculate the fac
ID: 3825383 • Letter: I
Question
Intel x86 Assembly
1. ( 9 points) 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 , u se WriteString and ReadDec (see assignment6 , question3 for a similar example)
- Pass the entered number to the Factorial subroutine
- The calculated n! needs to be display ed on console screen from main subroutine
- See the book page 305 - 306 where you will find main and factorial subroutine s .
- M ake the required changes and run the program
- Use Step Into instead of S tep O ver 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 ( 0x 4000407C ) .
Submit the following: Lastname1.asm
Explanation / Answer
A)
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
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.