how to find two numbers are equal or not.

Use CMP instruction

The CMP instruction compares two operands. It is generally used in conditional execution. This instruction basically subtracts one operand from the other for comparing whether the operands are equal or not.

Use JL instruction 

The JL instruction is a conditional jump that follows a test. It performs a signed comparison jump after a CMP if the destination operand is less than the source operand.


.model small
.data
n1 db "Enter first number:$"
n2 db 10d,"Enter second number:$"
msg1 db 10d,"numbers are equal$"
msg2 db 10d,"numbers are not equal$"

.code
mov ax,@data
mov ds,ax

mov ah,09h
mov dx,offset n1
int 21h

mov ah,01h
int 21h
mov bl,al
mov ah,09h
mov dx,offset n2
int 21h
mov ah,01h
int 21h
mov cl,al
cmp bl,cl
je eq1
mov ah,09h
mov dx,offset msg2
int 21h
jmp exit
eq1:
  mov ah,09h
  mov dx,offset msg1
  int 21h
exit:
mov ah,4ch
int 21h
end

Output:

how to check if two numbers are equal or not in assembly language


Comments