sara_84 4 Light Poster

hello all, i write a program in 8086 to compare between two numbers, but when i enter numbers 99 and 9 it give me tha same, also with other; (55=5,44=4...etc)
this this my code, how can i solve error.

.MODEL SMALL
.STACK 64 
.DATA
   MS1 DB 23 DUP('ENTER THE FIRST DIGIT: ')
   MS2 DB 23 DUP('ENTER THE SECOND DIGIT: ')
   MSG1 DB 26 DUP('FIRST DIGIT > SECOND DIGIT')
   MSG2 DB 26 DUP('FIRST DIGIT < SECOND DIGIT')
   MSG3 DB 26 DUP('FIRST DIGIT = SECOND DIGIT')
   ERROR_MSG DB 32 DUP('ENTER NUMBER BETWEEN 1 & 99 ONLY')
   NUM1 DB ?
   NUM2 DB ?
   TEN DB 10   
   E DB 0AH,0DH
   LEN1 DW ?
   LEN2 DW ?

.CODE
   MOV AX,@DATA
   MOV DS,AX

  CALL FIRST_DIGIT
  CALL SECOND_DIGIT

   XOR AX,AX        ;AX=0
   XOR BX,BX        ;BX=0 
   MOV AL,NUM1[SI]  
   MOV BL,NUM2[SI]
   CALL COMPARE
   JMP FINISH

;///////////////////////////////////
COMPARE PROC

   CMP AL,NUM2[SI]
   JG GREATER
   
   CMP AL,NUM2[SI]
   JL LESS
   CALL READ
   MOV CX,26
   LEA DX,MSG3
   INT 21H
   JMP FINISH
   

   GREATER:
   CALL READ
   MOV CX,26
   LEA DX,MSG1
   INT 21H
   JMP FINISH

   LESS:
   CALL READ
   MOV CX,26
   LEA DX,MSG2
   INT 21H
RET
COMPARE ENDP

FINISH:
   MOV AX,4C00H
   INT 21H 

;///////////////////////////////////
FIRST_DIGIT PROC

   CALL READ
   MOV CX,23
   LEA DX,MS1
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM1[SI]
   INT 21H
   
   SUB AX,2
   CMP NUM1[SI],99
   JG ERROR1

   CMP NUM1[SI],'0'
   JLE ERROR1
   MOV LEN1,AX
  
   MOV CX,LEN1
   MOV SI,0
   XOR BX,BX

   CMP NUM1[SI],9
   JG NEXT
   MOV AL,NUM1[SI]
   SUB AL,30H
   
ERROR1:
CALL ERROR_MESSEGE
JMP FINISH
  
NEXT:
   XOR AX,AX
   MOV AL,NUM1[SI]
   SUB AL,30H
   MOV BL,TEN
   MUL BL
   SUB AL,30H
   
RET
FIRST_DIGIT ENDP   

;///////////////////////////////////
SECOND_DIGIT PROC

   CALL READ
   MOV CX,23
   LEA DX,MS2
   INT 21H

   CALL WRITE
   MOV CX,7
   LEA DX,NUM2[SI]
   INT 21H 
   
   SUB AX,2
   CMP NUM2[SI],99
   JG ERROR2
   
   MOV LEN2,AX
  
   MOV CX,LEN2
   MOV SI,0
   XOR BX,BX

   CMP NUM2[SI],9
   JG NEXT1
   MOV AL,NUM2[SI]
   SUB AL,30H
   
ERROR2:
CALL ERROR_MESSEGE
JMP FINISH
   
NEXT1:
   XOR AX,AX
   MOV AL,NUM2[SI]
   SUB AL,30H
   MOV BL,TEN
   MUL BL
   SUB AL,30H

RET
SECOND_DIGIT ENDP 
 
;///////////////////////////////////   
READ PROC NEAR

   MOV AH,40H
   MOV BX,01H

RET
READ ENDP 
;///////////////////////////////////   
write PROC NEAR
   
   MOV AH,3FH
   MOV BX,00H
   
RET
WRITE ENDP
;///////////////////////////////////   
ERROR_MESSEGE PROC

   CALL READ
   MOV CX,32
   LEA DX,ERROR_MSG
   INT 21H
RET
ERROR_MESSEGE ENDP
;///////////////////////////////////
END
Salem commented: 25 posts, still no code tags. You really need to do better. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.