Question: Please code in 32 bit x86 assembly language Write a procedure named CheckPrime that sets the EBX register to 1 if the 32-bit integer passed
Please code in 32 bit x86 assembly language
Write a procedure named CheckPrime that sets the EBX register to 1 if the 32-bit integer passed in the EAX register is prime. If the 32-bit integer passed in the EAX register is not prime, then the procedure should set EBX to 0. Use the div instruction and a loop to determine if the user entered integer is prime by examining the div instructions remainder value.
Write a test program that prompts the user for an integer, calls CheckPrime, and displays a message indicating whether or not the user entered value is prime.
Submit your code (.asm file) that you have written
Please do not copy other people's answer as it is verified that it will not work. (see below)
GIVENTHAT :
The procedure is as below with requirement as - eax has number and need to find prime or not and set in ebx
CheckPrime PROC
MOV EDX,0
MOV ECX,2
MOV EBX,1
L1: CMP EAX,ECX
JE DONE
DIV ECX
INC ECX
CMP EDX,0
JNE L1
MOV EBX,0
DONE:
RET
CheckPrime ENDP
The program is as below.
Read input, call procedure and print output
DATA SEGMENT
A DD ?
MSG1 DB 10,13,"ENTER A NUMBER : $"
MSG2 DB 10,13,"Not Prime $"
MSG3 DB 10,13,"Prime $"
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 EAX,30H
MOV A,EAX
CALL CheckPrime
CheckPrime PROC
MOV EDX,0
MOV ECX,2
MOV EBX,1
L1: CMP EAX,ECX
JE DONE
DIV ECX
INC ECX
CMP EDX,0
JNE L1
MOV EBX,0
DONE:
RET
CheckPrime ENDP
CMP EBX,0
JE NOTPRIME
LEA DX,MSG3
JMP DONE1
NOTPRIME: LEA DX,MSG2
DONE1: MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
ENDS
END START
Hope u like this ans
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
