How to find which number is greater between two numbers.

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 JG instruction 

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


.model small
.data
n1 db "Enter first number:$"
n2 db 10d,"Enter second number:$"
n3 db 10d,"Greater number is:$"
.code
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset n1
int 21h
mov ah,01h
int 21h
sub al,30h
mov bl,al
mov ah,09h
mov dx,offset n2
int 21h
mov ah,01h
int 21h
sub al,30h
mov cl,al
mov ah,09h
mov dx,offset n3
int 21h

cmp bl,cl
jg gr
mov dl,cl
add dl,30h
mov ah,02h
int 21h
jmp exit
gr:
  mov dl,bl
  add dl,30h
  mov ah,02h
  int 21h
exit:
mov ah,4ch
int 21h
end

Output:

how to find greater number in assembly language program, how to find which number is greater between two numbers in assembly language program







Comments