flat assembler
Message board for the users of flat assembler.

Index > DOS > mov ah,al + div bl = crash ??

Author
Thread Post new topic Reply to topic
Karl20001



Joined: 10 Nov 2005
Posts: 11
Karl20001
Hi, i have discovered strange problem

Code:
use16
Org 0x100

 mov ax,$13
 int 10h

 mov ah,al ;<<---

 mov cx,dx
 add cx,10
 sub dx,20
 mov bx,cx

 mov bl,4  
 div bl      ;<<---

 call waitkey

exit:
 mov ax,$3
 int 10h
 int 20h

waitkey:
 push ax
 mov ah, 0
 int 16h
 pop ax
retn  
    


Normally it should go fullscreen and close on keypress. But it immediatly crashes. If i remove either mov ah,al or div bl it doesnt crash.
With xchg ah,al the same. The stuff in the middle is just to show that it crashes even when the 2 commands are seperated by other operations.
The mov bl,4 is to show that there is no divide by zero.
Btw. the code works if div bl is infront of mov ah,al.
I use fasm 1.67.14 and have no idea why this happens
Shocked
Post 16 Dec 2006, 13:04
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
Karl20001 wrote:
The mov bl,4 is to show that there is no divide by zero.

The exception 0, though sometimes called "division by 0" is really a "division overflow". It occurs when divisor is too small to get a correct result that would fit into the destination register (AL in this case, since DIV BL divides AX=AH:AL by BL and stores quotient in AL and remainder in AH.
In this case the result of division is simply too large to fit into AL and exception occurs.

In general, the exception 0 on 8-bit division will occur when divisor (in this case BL) is smaller or equal to AH. Similarly in case of 16-bit division the exception will happen when divisor isn't greater than DX, etc.
Post 16 Dec 2006, 13:22
View user's profile Send private message Visit poster's website Reply with quote
Karl20001



Joined: 10 Nov 2005
Posts: 11
Karl20001
Big thanks, i didnt know that Smile
Post 16 Dec 2006, 13:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.