1

Hey guys im trying to write a program which intakes 2 numbers from a user, between 1 and 2^32-1, after in taking the numbers i then check to see if they are "Amicable Numbers"

https://www.merriam-webster.com/dictionary/amicable%20number

I'm having an error with my Second Functions which check the Sum of the dividiors of Num1,when i input the umber 220 into Num1 variable, after 59 Cycles through the loop for some reason im getting "divided by zero" error, i have no clue what im doing wrong!

I have added a a SS to show where the error happens! enter image description here

       .MODEL SMALL
            .STACK 100h
            .386
            .DATA
PromptStr DB 13,10,'Please enter 2 numbers!',13,10,'$'
Amicable DB 13,10,'Amicable Numbers',13,10,'$'
NotAmicable DB 13,10,'Not Amicable numbers',13,10,'$'
Cnt1 DD 0
Cnt2 DD 0
Num1 DD 0
Num2 DD 0
Ten DD 10
TMP DD 0
TMP1 DD 0
Key DW 221
Check DB 2
           .CODE
getNum PROC NEAR
       MOV AX,0
       MOV AH,1
       INT 21h
       MOV AH,0
       SUB AL,'0'
       MOV CX,Key
       CMP CX,AX
       JE EndgetNum
       MOV ECX,0
       MOV ECX,EAX
       MOV EAX,EBX
       MUL Ten
       ADD EAX,ECX
       MOV EBX,0
       MOV EBX,EAX
       MOV ECX,0
       MOV EAX,0
       JMP getNum
EndgetNum:
       MOV EAX,0
       MOV EAX,EBX
       RET
    getNum ENDP
PNum PROC NEAR
        MOV ECX,0
        MOV EDX,0
        MOV ECX,Num1
        MOV TMP,ECX
        MOV ECX,0
        MOV ECX,EAX
        DEC ECX
Cnt:
        MOV EAX,0
        MOV EAX,TMP
        MOV EBX,0
        MOV EBX,ECX
        DIV EBX
        MOV EBX,0
        CMP EBX,EDX
        JE ModIsZero
        LOOP Cnt
        MOV EAX,0
        MOV EAX,TMP1
        RET
        PNum ENDP

ModIsZero:
        ADD TMP1,ECX
        LOOP Cnt
ProgStart:
        MOV AX,@DATA
        MOV DS,EAX
        MOV DX,OFFSET PromptStr
        MOV AH,9
        INT 21h
        MOV EBX,0
        MOV EAX,0
        CALL getNum
        MOV Num1,EAX
        MOV EBX,0
        MOV EAX,0
        CALL getNum
        MOV Num2,EAX
        MOV EAX,0
        MOV EAX,Num1
        MOV EBX,0
        MOV EBX,2
        DIV EBX
        CALL PNum
        MOV AH,4Ch
        INT 21h
        END ProgStart
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Soske
  • 541
  • 1
  • 4
  • 10

0 Answers0