divdi.s 893 B

12345678910111213141516171819202122232425262728293031323334353637
  1. |divdi3 routine copyright (C) 2002, Kevin Kofler
  2. |WARNING: Division by 0 will be handled the same way as in the unsigned variant.
  3. | For my __udivdi3, this means:
  4. | A division by 0 will not cause an exception, but just crash in an
  5. | infinite loop!
  6. |ANOTHER WARNING: This will ONLY work with an __udivdi3 which does NOT destroy a1!
  7. | Mine works of course.
  8. .data
  9. xdef __divdi3
  10. .even
  11. __divdi3:
  12. tst.b 4(%a7)
  13. blt.s .L__divdi3_numer_negative
  14. tst.b 12(%a7)
  15. blt.s .L__divdi3_denom_negative
  16. .L__divdi3_udivdi3:
  17. jbra __udivdi3
  18. .L__divdi3_numer_negative:
  19. neg.l 8(%a7)
  20. negx.l 4(%a7)
  21. tst.b 12(%a7)
  22. bge.s .L__divdi3_denom_positive
  23. neg.l 16(%a7)
  24. negx.l 12(%a7)
  25. bra.s .L__divdi3_udivdi3
  26. .L__divdi3_denom_negative:
  27. neg.l 16(%a7)
  28. negx.l 12(%a7)
  29. .L__divdi3_denom_positive:
  30. move.l (%a7)+,%a1
  31. bsr.s .L__divdi3_udivdi3
  32. neg.l %d1
  33. negx.l %d0
  34. jmp (%a1)