I have made a code for finding out all the factors of a given number in 8086 assembly language. But the problem is I am getting wrong output if the factors are more than 9. For example: when the input is 54 I am getting the correct result but when the input is 72 i am getting wrong output . How will i show the output if the result is greater than 9?
Here is my code :
.MODEL SMALL
.STACK 100
.DATA
NUMBER DW 72
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AX,NUMBER ; storing the dividend
MOV BX,1 ; storing the divisor (starting from 1)
MOV CX,0 ; initially all factors are zero
WHILE_:
XOR DX,DX ;clearing the bit fields
DIV BX
CMP DX,0 ; checking if remainder is 0
JE CHECK
MOV AX,NUMBER
INC BX ;incrementing divisor
CMP BX,AX ; checking if dividend is less then divisor
JL WHILE_ ;
JMP END_ ; if so then ends
CHECK:
CMP AX,BX
JG INC_ ;jump if divisor is smaller than dividend
JE INC2_ ;jump if divisor= dividend
JMP END_
INC_:
ADD CX,2 ; incrementing by 2 as we are getting to factors: divisor and the quotient
MOV AX,NUMBER
INC BX ;incrementing divisor
CMP BX,AX ;checking if dividend is less then divisor
JL WHILE_:
JMP END_
INC2_:
INC CX ; incrementing counter single time as we are getting two same factors
JMP END_
END_:
CMP CX,10
JL PRINT1:
JMP PRINT2
PRINT1:
ADD CX,48 ; printing decimal value
MOV AH,2
MOV DX,CX
INT 21H
MOV AH,4CH
INT 21H
PRINT2:
ADD CX,48 ; printing decimal value
MOV AH,2
MOV DX,CX
INT 21H
MOV AH,4CH
INT 21H
MAIN ENDP
END MAIN
RET
How will I improve this code? Is there any way to show the output is this case?