moddivsi3.S 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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:16
  14. mov.l er3,er0
  15. rts
  16. .global __divsi3
  17. __divsi3:
  18. PUSHP S2P
  19. bsr divnorm
  20. bsr __udivsi3:16
  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