ror.s 503 B

123456789101112131415161718192021222324252627282930
  1. .define Ror
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine rotates right a integer twobyte word.
  8. ! The number of rotates is in X.
  9. ! The result is returned in registerpair AX.
  10. Ror:
  11. txa
  12. bne 1f ! a zero rotate just return input
  13. jmp Pop
  14. 1: tay
  15. jsr Pop ! get word
  16. stx Ytmp ! save lowbyte
  17. 2: clc
  18. ror a ! rotate highbyte
  19. ror Ytmp ! rotate lowbyte
  20. bcc 1f ! no carry
  21. ora #0x80 ! put carry in leftmost bit
  22. 1: dey
  23. bne 2b
  24. ldx Ytmp ! get lowbyte
  25. rts