So this is my first time writing a post here. I'm very new to the assembly language and started the learning journey with emu8086.
Recently I wrote a program that detects if the number entered is either positive or negative and determines whether it's a prime number or not. I made it the first part (detecting positive or negative numbers, using array), but for some reason it keeps saying "Not a prime number" for any numbers I enter.
I tried to get it to copy the number stored in the array and bring it over to the prime/not prime section of the program but to not avail.
Anyone know what exactly the problem is? I'm pretty lost right now.
Here's the code I wrote:
.MODEL SMALL
.STACK 100H
.DATA
ARRAY DB DUP('$')
NUM DB ?
MSG1 DB 0AH,0DH,'ENTER YOUR DESIRED NUMBER:','$'
MSG2 DB 0AH,0DH,'NOT A PRIME NUMBER','$'
MSG3 DB 0AH,0DH,'A PRIME NUMBER','$'
POSI DB 0AH,0DH,'A POSITIVE NUMBER','$'
NEGA DB 0AH,0DH,'A NEGATIVE NUMBER','$'
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV SI, OFFSET ARRAY
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
CMP AL,13
JE CHECK
MOV [SI],AL
INC SI
JMP L1
L1:
MOV AH,1
INT 21H
CMP AL,13
JE CHECK
MOV [SI],AL
INC SI
JMP L1
CHECK:
CMP ARRAY, '-' ;IF ARRAY CONTAINS - SIGN THEN THE NUMBER IS NEGATIVE
JE L2
MOV DX, OFFSET POSI
MOV AH,9
INT 21H
JMP EXIT1
L2:
MOV DX, OFFSET NEGA
MOV AH,9
INT 21H
EXIT1:
mov al, [NUM]
mov bl, al
sub al, 2
mov cl, al ; counter value
; original input
mov dl, 2
l3:
mov ax, bx
div dl
cmp ah, 0h
jz pnot
inc dl
loop l3
mov ah, 9h
lea dx, msg3
int 21h
jmp end
pnot:
mov ah, 9h
lea dx, msg2
int 21h
END:
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
Any help would be greatly appreciated, thank you in advance!