🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #847

Re: This is strange, div doesn't work....

#847
From: Joi L. Ellis
Date: Sun, 20 Dec 1992 06:06
44 lines
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
Technical Details
Message-ID: <BzJnMz.Gq4@uxa.ecn.bgu.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!uwm.edu!psuvax1!news.ecn.bgu.edu!uxa.ecn.bgu.edu!msjle
References: <1gp6q9INNgdd@aludra.usc.edu> <1992Dec18.094825.14710@miavx1.acs.muohio.edu> <BzIxL9.28B@undergrad.math.waterloo.edu>

Show Full Headers
Complete Article Headers
Newsgroups: alt.msdos.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!uwm.edu!psuvax1!news.ecn.bgu.edu!uxa.ecn.bgu.edu!msjle
From: msjle@uxa.ecn.bgu.edu (Joi L. Ellis)
Subject: Re: This is strange, div doesn't work....
Message-ID: <BzJnMz.Gq4@uxa.ecn.bgu.edu>
Organization: Educational Computing Network
References: <1gp6q9INNgdd@aludra.usc.edu> <1992Dec18.094825.14710@miavx1.acs.muohio.edu> <BzIxL9.28B@undergrad.math.waterloo.edu>
Date: Sun, 20 Dec 1992 06:06:35 GMT
Lines: 45