home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / alt / msdos / programm / 2974 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.1 KB  |  56 lines

  1. Newsgroups: alt.msdos.programmer
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!psuvax1!news.ecn.bgu.edu!uxa.ecn.bgu.edu!msjle
  3. From: msjle@uxa.ecn.bgu.edu (Joi L. Ellis)
  4. Subject: Re: This is strange, div doesn't work....
  5. Message-ID: <BzJnMz.Gq4@uxa.ecn.bgu.edu>
  6. Organization: Educational Computing Network
  7. References: <1gp6q9INNgdd@aludra.usc.edu> <1992Dec18.094825.14710@miavx1.acs.muohio.edu> <BzIxL9.28B@undergrad.math.waterloo.edu>
  8. Date: Sun, 20 Dec 1992 06:06:35 GMT
  9. Lines: 45
  10.  
  11. rtczegle@undergrad.math.waterloo.edu (Richard Czegledi) writes:
  12.  
  13. >In article <1992Dec18.094825.14710@miavx1.acs.muohio.edu> sjmadsen@apsvax.aps.muohio.edu (Steve Madsen) writes:
  14. >>Michael Duffy (mduffy@aludra.usc.edu) wrote:
  15. >>: The following code gives me a divide error:
  16. >>: 
  17. >>:  mov  ax,0035h
  18. >>:  mov  dx,01h
  19. >>:  div  dx
  20. >>:
  21. >>
  22. >>    I'm not a genius at assembler, but after looking in my TASM 3.2
  23. >>quick-ref, this is about the only thing I could come up with:
  24. >>
  25. >>    What it appears is that you are doing a simple 16-bit divide.
  26. >>As far as my manual is concerned, if you do a div instruction with a
  27. >>16-bit operand (such as dx in your example), then it uses DX:AX as your
  28. >>dividend.  This might be why you are having a problem, but it's only a
  29. >>guess.
  30. >>
  31. >>    You could try changing DX to DL and see if that works.  Since
  32. >>you are assigned DX to what looks like a byte value anyway, this might
  33. >>solve your problem. 
  34.  
  35. >You are getting divide errors because the quotient cannot be stored within
  36. >a 16 bit registers (ie. AX).  Division on an 80x86 stores the quotient in AX
  37. >and the remainder in DX assuming that you are performing 16 bit divisions.
  38. >I think that you have to check that the quotient will not be larger than
  39. >16 bits before performing the division. 
  40.  
  41. The problem here is that it is illegal to use DX for the operand in a
  42. sixteen-bit divide, because the microcode will mangle it in the course
  43. of the operation.  If he uses
  44.    DIV CX
  45. instead of 
  46.    DIV DX
  47. it will work just fine.
  48.  
  49. BTW:  How would he check what the quotient will be over 16 bits, on a 16
  50. bit CPU??  It doesn't *care*.
  51.  
  52. -- 
  53. Joi Ellis                      msjle@uxa.ecn.bgu.edu
  54. Student Residential Programs   Western Illinois University
  55.  
  56.