2 ; Ullrich von Bassewitz, 2004-06-30
4 ; CC65 runtime: right shift support for unsigneds
6 ; Note: The standard declares a shift count that is negative or >= the
7 ; bitcount of the shifted type for undefined behaviour.
9 ; Note^2: The compiler knowns about the register/zero page usage of this
10 ; function, so you need to change the compiler source if you change it!
14 .export tosshrax, shraxy
19 sta tmp1 ; Save shift count
20 jsr popax ; Get the left hand operand
21 ldy tmp1 ; Get shift count
29 beq L2 ; Nothing to shift
31 sbc #8 ; Shift count 8 or greater?
32 beq L3 ; Jump if exactly 8
33 bcc L4 ; Jump if less than 8
35 ; Shift count is greater than 8.
37 tay ; Shift count into Y
38 pla ; Discard low byte
44 ldx #$00 ; High byte is zero
52 ; Shift count is exactly 8
54 L3: pla ; Drop low byte from stack ...
55 txa ; Move high byte to low
56 ldx #$00 ; Clear high byte
59 ; Shift count is less than 8
61 L4: adc #8 ; Correct counter
62 tay ; Shift count into Y
63 pla ; Restore low byte
64 stx tmp1 ; Save high byte of lhs