userqt 0 Newbie Poster

That's the program I'm trying to wrote:

.model small
.stack 100h
.data
x dw 2
array db 100 dup(?)
even db 0 
unread db 0 
len=($-array)
.code
mov ax,@data
mov ds,ax
mov CX,len
mov SI,0
m1:      
mov ah,08h  ;inputs a digit into al
int 21h
cmp al,27  ;is it esc?
je m7        ;go to m7!
cmp al,13    ;is it enter?
je m7
cmp al,'0'  ;is it 0? if so, go to m2
je m2
cmp al,'1'  ;s it 1? if so, go to m2
je m2
cmp al,'2'  ;etc...
je m2
cmp al,'3'
je m2
cmp al,'4'
je m2
cmp al,'5'
je m2
cmp al,'6'
je m2
cmp al,'7'
je m2
cmp al,'8'
je m2
cmp al,'9'
je m2
jmp m1  ;if it's not esc, enter or digit then it's gotta be letter or contor symbol


m2:          ;this print inputed digit
mov dl,al
mov ah,02h
int 21h
mov [SI+array],dl    ;write's the digit from dl into the array
add SI,2                 ;go to the array's next element
jmp m1         ;get's back to input another digit

m7:
mov si,0    
m8: 
mov dl,[SI+array]  ;read's a element from the array
mov ax,x    ;make's ax 2
div dl          ;divide's the element to 2 [icode]The problem is around here somwehre here![/icode]
cmp ah,0   ;if the remainder is zero, then the digit is even
inc even    ;incerase even (stores the number of even digits)
inc unread    ;else incerase unread (i'm not sure about this but I can fix it later, this is not what's causе the problem)
inc si      ;incerase source index
loop m8    ;loop 'till reach the end of the array - len
jmp the_end

the_end:
mov dl,even  ;trying to print the number of the even digits (not sure it will work)
mov ah,02h
int 21h
mov ah,4ch  ;return to operating system
int 21h
end

The point is to enter only digits and then to write them down to an array. Then I have to print the number of even and unread digits.
But I don't want help on this.

I just want to know why give's me the error "Divide overflow".
I start the program, write some digits and when I hit "enter" or "Esc" I get "Divide overflow".

The problem is somewere here

mov ax,x   
div dl         

I knew it!

Any help? Thanks!

(btw sorry for my crappy english, I'm from mars :)

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.