modsi3.S 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "libgcc.h"
  2. ; numerator in A0/A1
  3. ; denominator in A2/A3
  4. .global __modsi3
  5. __modsi3:
  6. PUSHP S2P
  7. bsr modnorm
  8. bsr __divsi3
  9. mov.l er3,er0
  10. bra exitdiv
  11. .global __umodsi3
  12. __umodsi3:
  13. bsr __udivsi3
  14. mov.l er3,er0
  15. rts
  16. .global __divsi3
  17. __divsi3:
  18. PUSHP S2P
  19. jsr divnorm
  20. bsr __udivsi3
  21. ; examine what the sign should be
  22. exitdiv:
  23. btst #3,S2L
  24. beq reti
  25. ; should be -ve
  26. neg.l A0P
  27. reti:
  28. POPP S2P
  29. rts
  30. divnorm:
  31. mov.l A0P,A0P ; is the numerator -ve
  32. stc ccr,S2L ; keep the sign in bit 3 of S2L
  33. bge postive
  34. neg.l A0P ; negate arg
  35. postive:
  36. mov.l A1P,A1P ; is the denominator -ve
  37. bge postive2
  38. neg.l A1P ; negate arg
  39. xor.b #0x08,S2L ; toggle the result sign
  40. postive2:
  41. rts
  42. ;; Basically the same, except that the sign of the divisor determines
  43. ;; the sign.
  44. modnorm:
  45. mov.l A0P,A0P ; is the numerator -ve
  46. stc ccr,S2L ; keep the sign in bit 3 of S2L
  47. bge mpostive
  48. neg.l A0P ; negate arg
  49. mpostive:
  50. mov.l A1P,A1P ; is the denominator -ve
  51. bge mpostive2
  52. neg.l A1P ; negate arg
  53. mpostive2:
  54. rts
  55. .end