Thread View: alt.msdos.programmer
7 messages
7 total messages
Started by Michael Duffy
Thu, 17 Dec 1992 06:30
This is strange, div doesn't work....
Author: Michael Duffy
Date: Thu, 17 Dec 1992 06:30
Date: Thu, 17 Dec 1992 06:30
12 lines
799 bytes
799 bytes
I hope someone can help me, 'cause I'm at a loss. The following code gives me a divide error: mov ax,0035h mov dx,01h div dx It should work. I don't know why it doesn't. Could some assembly language genius please show me the light? E-mail please since I don't check this group very often. Thank you much, Michael Duffy (mduffy@aludra.usc.edu)
Re: This is strange, div doesn't work....
Author: Steve Madsen
Date: Fri, 18 Dec 1992 14:48
Date: Fri, 18 Dec 1992 14:48
20 lines
1210 bytes
1210 bytes
Michael Duffy (mduffy@aludra.usc.edu) wrote: : The following code gives me a divide error: : : mov ax,0035h : mov dx,01h : div dx : I'm not a genius at assembler, but after looking in my TASM 3.2 quick-ref, this is about the only thing I could come up with: What it appears is that you are doing a simple 16-bit divide. As far as my manual is concerned, if you do a div instruction with a 16-bit operand (such as dx in your example), then it uses DX:AX as your dividend. This might be why you are having a problem, but it's only a guess. You could try changing DX to DL and see if that works. Since you are assigned DX to what looks like a byte value anyway, this might solve your problem.
Re: This is strange, div doesn't work....
Author: Scott C. Sadow
Date: Sat, 19 Dec 1992 15:49
Date: Sat, 19 Dec 1992 15:49
28 lines
1198 bytes
1198 bytes
In article <1gp6q9INNgdd@aludra.usc.edu>, Michael Duffy (mduffy@aludra.usc.edu) writes: >I hope someone can help me, 'cause I'm at a loss. > >The following code gives me a divide error: > > mov ax,0035h > mov dx,01h > div dx > >It should work. I don't know why it doesn't. Could some assembly language >genius please show me the light? E-mail please since I don't check this >group very often. Thank you much, >Michael Duffy (mduffy@aludra.usc.edu) > The problem is that "DIV <word>" means to divide DX:AX by <word>. Therefore, the above example is dividing "00010035H" by "0001". This causes a divide error because the result cannot fit in one word. Try the following instead: MOV AX,0035H XOR DX,DX MOV BX,01H DIV BX (this answer was posted because it seemed like something many people w
Re: This is strange, div doesn't work....
Author: Richard Czegledi
Date: Sat, 19 Dec 1992 20:43
Date: Sat, 19 Dec 1992 20:43
27 lines
1715 bytes
1715 bytes
In article <1992Dec18.094825.14710@miavx1.acs.muohio.edu> sjmadsen@apsvax.aps.muohio.edu (Steve Madsen) writes: >Michael Duffy (mduffy@aludra.usc.edu) wrote: >: The following code gives me a divide error: >: >: mov ax,0035h >: mov dx,01h >: div dx >: > > I'm not a genius at assembler, but after looking in my TASM 3.2 >quick-ref, this is about the only thing I could come up with: > > What it appears is that you are doing a simple 16-bit divide. >As far as my manual is concerned, if you do a div instruction with a >16-bit operand (such as dx in your example), then it uses DX:AX as your >dividend. This might be why you are having a problem, but it's only a >guess. > > You could try changing DX to DL and see if that works. Since >you are assigned DX to what looks like a byte value anyway, this might >solve your problem. You are getting divide errors because the quotient cannot be stored within a 16 bit registers (ie. AX). Division on an 80x86 stores the quotient in AX and the remainder in DX assuming that you are performing 16 bit divisions. I think that you have to check that the quotient will not be larger than 16 bits before performing the division.
Re: This is strange, div doesn't work....
Author: Joi L. Ellis
Date: Sun, 20 Dec 1992 06:06
Date: Sun, 20 Dec 1992 06:06
44 lines
2250 bytes
2250 bytes
rtczegle@undergrad.math.waterloo.edu (Richard Czegledi) writes: >In article <1992Dec18.094825.14710@miavx1.acs.muohio.edu> sjmadsen@apsvax.aps.muohio.edu (Steve Madsen) writes: >>Michael Duffy (mduffy@aludra.usc.edu) wrote: >>: The following code gives me a divide error: >>: >>: mov ax,0035h >>: mov dx,01h >>: div dx >>: >> >> I'm not a genius at assembler, but after looking in my TASM 3.2 >>quick-ref, this is about the only thing I could come up with: >> >> What it appears is that you are doing a simple 16-bit divide. >>As far as my manual is concerned, if you do a div instruction with a >>16-bit operand (such as dx in your example), then it uses DX:AX as your >>dividend. This might be why you are having a problem, but it's only a >>guess. >> >> You could try changing DX to DL and see if that works. Since >>you are assigned DX to what looks like a byte value anyway, this might >>solve your problem. >You are getting divide errors because the quotient cannot be stored within >a 16 bit registers (ie. AX). Division on an 80x86 stores the quotient in AX >and the remainder in DX assuming that you are performing 16 bit divisions. >I think that you have to check that the quotient will not be larger than >16 bits before performing the division. The problem here is that it is illegal to use DX for the operand in a sixteen-bit divide, because the microcode will mangle it in the course of the operation. If he uses DIV CX instead of DIV DX it will work just fine. BTW: How would he check what the quotient will be over 16 bits, on a 16 bit CPU?? It doesn't *care*. -- Joi Ellis msjle@uxa.ecn.bgu.edu Student Residential Programs Western Illinois University
Re: This is strange, div doesn't work....
Author: Tom Leylan
Date: Sun, 20 Dec 1992 07:34
Date: Sun, 20 Dec 1992 07:34
21 lines
858 bytes
858 bytes
mduffy@aludra.usc.edu (Michael Duffy) writes: >The following code gives me a divide error: > > mov ax,0035h > mov dx,01h > div dx > >It should work. I don't know why it doesn't. Could some assembly language >genius please show me the light? I believe you want: mov dl, 01h div dl The problem disappears and hopefully you get the right answer. tom <email coming your way also>
Re: This is strange, div doesn't work....
Author: Charles M. Heard heard
Date: Sun, 20 Dec 1992 07:34
Date: Sun, 20 Dec 1992 07:34
25 lines
1565 bytes
1565 bytes
Michael Duffy (mduffy@aludra.usc.edu) wrote: >: The following code gives me a divide error: >: >: mov ax,0035h >: mov dx,01h >: div dx Yes indeed. The 80x86 will give you a divide error anytime the quotient is too large to fit into the destination register. This code divides the 32-bit unsigned integer in DX:AX -- namely 010035H -- by the 16-bit unsigned integer in DX -- namely 0001H -- and is supposed to return the quotient -- 010035H -- in AX (with the remainder in DX). It won't fit, so a divide exception is raised. In article <1992Dec18.094825.14710@miavx1.acs.muohio.edu> sjmadsen@apsvax.aps.muohio.edu (Steve Madsen) writes: > You could try changing DX to DL and see if that works. Since >you are assigned DX to what looks like a byte value anyway, this might >solve your problem. This will not raise the exception, but it changes the instruction semantics. It divides the 16-bit unsigned number in AX by the 8-bit number in DL and returns the quotient in AL and the remainder in AH. So "div dl" would function as a no-op with 0035H in AX and 01H in DL. heard
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads