push_shortint.s 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. .xdef push_shortint
  2. .text
  3. push_shortint:
  4. | Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack.
  5. | Only two are needed, but this is smaller than subtracting and adding.
  6. movem.l %d2-%d6/%a5,-(%sp)
  7. | Put address of push_quantum into %a5.
  8. move.l 0xC8,%a5
  9. move.l (%a5,3000),%a5 /* push_quantum */
  10. | %d4: Number of bytes.
  11. clr.w %d4
  12. | Put POSINT_TAG in %d6.
  13. moveq.l #31,%d6
  14. | Move parameter to %d3.
  15. move.w 28(%sp),%d3
  16. | If it is zero, the value should be zero bytes long.
  17. jbeq .L__finished
  18. | If negative, put NEGINT_TAG in %d6 and negate it.
  19. jbge .L__mainloop
  20. moveq.l #32,%d6
  21. neg.w %d3
  22. .L__mainloop:
  23. | Push rightmost quantum of the value.
  24. move.w %d3,(%sp)
  25. jsr (%a5)
  26. | Add 1 to the number of bytes.
  27. addq.w #1,%d4
  28. | Shift the value to the right by one quantum.
  29. lsr.w #8,%d3
  30. | Finished if remaining value is zero.
  31. jbne .L__mainloop
  32. .L__finished:
  33. | Push number of bytes.
  34. move.w %d4,(%sp)
  35. jsr (%a5)
  36. | Push tag.
  37. move.w %d6,(%sp)
  38. jsr (%a5)
  39. | See above.
  40. | There is no problem in "restoring" %d2, since it may be trashed.
  41. movem.l (%sp)+,%d2-%d6/%a5
  42. rts