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!
19 and #$0F ; Bring the shift count into a valid range
22 jsr popax ; Get the left hand operand
24 ldy tmp1 ; Get shift count
25 beq L9 ; Bail out if shift count zero
27 cpy #8 ; Shift count 8 or greater?
30 ; Shift count is greater 7. The carry is set when we enter here.
34 tay ; Adjust shift count
36 ldx #$00 ; Shift by 8 bits
37 beq L2 ; Branch always
43 ; Shift count is less than 8. Do the actual shift.
45 L3: stx tmp1 ; Save high byte of lhs