divide overflow issue

Reply

Join Date: Mar 2008
Posts: 5
Reputation: loudstil is an unknown quantity at this point 
Solved Threads: 0
loudstil loudstil is offline Offline
Newbie Poster

divide overflow issue

 
0
  #1
Jan 4th, 2009
Hi to all,
I wrote a code, and it gives me divide overflow, but the issue here is that when I run the program trough the debugger it works fine, but when I run the program in the dos mode it gives me Divide overflow error. here the code:
  1. prt_sig:
  2. mov al,[bx+si]
  3. mov ah,0
  4. ;the maximum digit in a number is 3
  5. push cx
  6. mov cx,3
  7. pr:
  8. xor dx,dx
  9. push bx
  10. mov bx,10
  11. div bx
  12. add dl,30h
  13. pop bx
  14. push dx
  15. xor ah,ah
  16. dec cx
  17. cmp cx,0
  18. jne pr
  19. mov cx,3
  20. prin:
  21. pop dx
  22. mov ah,02h
  23. int 21h
  24. loop prin

tnx
Last edited by Ancient Dragon; Jan 4th, 2009 at 6:12 pm. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 129
Reputation: Evenbit is on a distinguished road 
Solved Threads: 4
Evenbit's Avatar
Evenbit Evenbit is offline Offline
Junior Poster

Re: divide overflow issue

 
0
  #2
Jan 5th, 2009
Originally Posted by loudstil View Post
Hi to all,
I wrote a code, and it gives me divide overflow, but the issue here is that when I run the program trough the debugger it works fine, but when I run the program in the dos mode it gives me Divide overflow error. here the code:

tnx
Insert a CWD instruction right before the DIV instruction. This will sign-extend AX into the DX:AX pair needed for the ('dword' divided by 'word') division.

Nathan.
while (CPU is present) {some assembly required}
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 5
Reputation: loudstil is an unknown quantity at this point 
Solved Threads: 0
loudstil loudstil is offline Offline
Newbie Poster

Re: divide overflow issue

 
0
  #3
Jan 5th, 2009
Originally Posted by Evenbit View Post
Insert a CWD instruction right before the DIV instruction. This will sign-extend AX into the DX:AX pair needed for the ('dword' divided by 'word') division.

Nathan.
Thanks for the fast replay

I tried to put cwd before the DIV instruction, but it still gives me DIVIDE OVERFLOW.....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC