home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 255.lha / DivideZero / DivZero.asm < prev    next >
Assembly Source File  |  1989-06-07  |  1KB  |  62 lines

  1.   ;Divide by zero cpu exeption trap
  2.   ;cpu exeption 5 ,will cause a Guru 00000005.xxxxxxxx
  3.   ;Div by zero error will come up when the cpu uses Divs,Divu if the 
  4.   ;denominator is so small that the cpu rounds it to zero,if it is
  5.   ;smaller then a word because Divs,Divu only uses words.
  6.   ;this little bit of code stops guru 5 and sets the answer to Div by zero
  7.   ;to computer infinity i.e. for Divs $FFF and for Divu $FFFF. you may say 
  8.   ;why do this, well if the number in the denominator is so small anyway then 
  9.   ;the answer to the division will be very large so we set the answer to
  10.   ;infinity,and go on. in almost all cases the program that caused the div by
  11.   ;zero will work just fine with the answer at infinity.  
  12.   ;to use this program just put Divzero in your startup-sequence
  13.   ;it will do the work of traping the exception 5 and stopping guru
  14.  
  15.  
  16. Init_Trap:
  17.   Move.l 4,A6
  18.   Move.l #Div_End-Div,D0
  19.  
  20.   MoveQ  #1,D1
  21.   Jsr    -198(a6)
  22.   Move.l  D0,New_Trap
  23.  
  24.   Beq.s  Init_End
  25.   Move.l D0,A1
  26.   Lea    Div,A0
  27.  
  28.   MoveQ  #(Div_End-Div)-1,D0
  29. Copy_Code:
  30.   Move.b (A0)+,(A1)+
  31.   DBra   D0,Copy_Code
  32.   Move.l New_Trap,20
  33.  
  34.  
  35. Init_End:
  36.   MoveQ  #0,D0
  37.   Divu   D0,D1
  38.   rts
  39.  
  40. New_Trap:
  41.   dc.l   0
  42.  
  43. Div:
  44.   MoveM.l D0-A6,-(sp)
  45.   Move.l  62(sp),A0
  46.   Move.w  -2(A0),D0
  47.   Move.l  #$ffff,D1
  48.  
  49.   Btst    #8,D0
  50.   Beq.s   GoOn
  51.   Move.l  #$7fff,D1
  52.  
  53. GoOn:
  54.   Lsr.w   #7,D0
  55.   AndI.l  #28,D0
  56.  
  57.   Move.l  D1,0(sp,d0.l)
  58.   MoveM.l (sp)+,D0-A6
  59.   Rte
  60. Div_End:
  61.  
  62.   END