Question: i need help with my masm x 8 6 program, its not returning prime for prime numbers, it returns not prime for prime numbers this

i need help with my masm x86 program, its not returning prime for prime numbers, it returns not prime for prime numbers
this is the logic:
int prime (int n){
int i, c =0;
for (i =1; i <= n; i++){
if (n % i ==0){
c++;
}
}
if (c ==2){
n is a Prime number.
}
else {
n is not a Prime number.
}
}
code:
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
INCLUDE C:\Users\copya\OneDrive\Documents\source\Irvine\Irvine32.inc
includelib C:\Users\copya\OneDrive\Documents\source\Irvine\irvine32.lib
.data
prompt1 BYTE "PRIME", 0
prompt2 BYTE "Not PRIME", 0
n DWORD 41
.code
main PROC
mov eax, n
mov ecx, 0
mov esi, 2
CheckFactors:
mov edx, 0
div esi
test edx, edx
jnz NotPrime
inc ecx
cmp ecx, 2
jg NotPrime
inc esi
cmp esi, eax
jle CheckFactors
Prime:
mov edx, OFFSET prompt1
jmp PrintResult
NotPrime:
mov edx, OFFSET prompt2
PrintResult:
call WriteString
call Crlf
invoke ExitProcess, 0
main ENDP
END main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!