Results 1 to 5 of 5

Thread: Divide Overflow??

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  2. #2
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  3. #3
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Divide Overflow??

    Quote 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

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    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.

  5. #5
    Hyperactive Member Maven's Avatar
    Join Date
    Feb 2003
    Location
    Greeneville, TN
    Posts
    322

    Re: Divide Overflow??

    Quote 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
  •  



Click Here to Expand Forum to Full Width