|
-
Dec 4th, 2005, 11:08 AM
#1
Divide Overflow??
Code:
mov eax, 1193180 ; a constant
movzx ebx, BYTE PTR [si]
div ebx ;divide overflow here :(
I can't figure out how to get around this problem. How can this cause an overflow? Dividing 1193180 by any number from 1 to 255 cause an overflow (I'm filtering out zero)?
This is for a little 16 bit program that is supposed to play a tune on the PC Speaker. The number i'm dividing by is a frequency of the note I want to play (in hertz).
I'm using this site as my guidance on this topic...
http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
How can I get past this problem???
I don't live here any more.
-
Jan 9th, 2006, 11:44 PM
#2
Fanatic Member
Re: Divide Overflow??
I just read up on using the div instruction since I havent covered that yet (im teaching myself asm). It appears that both edx and eax registers must be initalized first. Here is my example:
Code:
.data
var1 byte 255
.code
mov edx,0
mov eax,01193180h
div var1
I should point out that you mentioned this is a 16-bit program, yet you are using 32 bit registers. I assume it matters which ones you use?
For 16 bit replace edx with dx and eax with ax
Last edited by nkad; Jan 9th, 2006 at 11:53 PM.
-
Jan 17th, 2006, 02:51 PM
#3
Hyperactive Member
Re: Divide Overflow??
 Originally Posted by wossname
Code:
mov eax, 1193180 ; a constant
movzx ebx, BYTE PTR [si]
div ebx ;divide overflow here :(
I can't figure out how to get around this problem. How can this cause an overflow? Dividing 1193180 by any number from 1 to 255 cause an overflow (I'm filtering out zero)?
This is for a little 16 bit program that is supposed to play a tune on the PC Speaker. The number i'm dividing by is a frequency of the note I want to play (in hertz).
I'm using this site as my guidance on this topic...
http://fly.cc.fer.hr/GDM/articles/sndmus/speaker1.html
How can I get past this problem???
Well first off you shouldn't be able to use eax in a 16 bit enviroment. Another thing in a 16 bit enviroment, dx is the high part of a dividend. So you have to zero it out before using div.
What compiler are you using?
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
-
Jan 23rd, 2006, 02:17 PM
#4
Re: Divide Overflow??
16 bits i just the addressing system isnt it? I've had no problems using 32 bit registers in realmode for ages. Thats how fast graphics manipulation is perfomed, by shoving data around in 4byte chunks.
I'm on MASM. but this question is way out of date now and I'm no longer interested in it
I don't live here any more.
-
Jan 24th, 2006, 01:50 PM
#5
Hyperactive Member
Re: Divide Overflow??
 Originally Posted by wossname
16 bits i just the addressing system isnt it? I've had no problems using 32 bit registers in realmode for ages. Thats how fast graphics manipulation is perfomed, by shoving data around in 4byte chunks.
I'm on MASM. but this question is way out of date now and I'm no longer interested in it
Yea it's memory addressing.
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|