2 ; Ullrich von Bassewitz, 1998-08-05, 2004-06-25
4 ; CC65 runtime: left shift support for ints and 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 tosaslax, tosshlax, aslaxy, shlaxy
22 sta tmp1 ; Save shift count
23 jsr popax ; Get the left hand operand
24 ldy tmp1 ; Get shift count
33 beq L2 ; Nothing to shift
35 sbc #8 ; Shift count 8 or greater?
36 beq L3 ; Jump if exactly 8
37 bcc L4 ; Jump if less than 8
39 ; Shift count is greater than 8.
41 tay ; Shift count into Y
56 ; Shift count is exactly 8
58 .if (.cpu .bitand CPU_ISET_65SC02)
59 L3: plx ; Low byte from stack into X
60 rts ; A is already zero
62 L3: pla ; Low byte from stack ...
64 lda #$00 ; Clear low byte
68 ; Shift count is less than 8
70 L4: adc #8 ; Correct counter
71 tay ; Shift count into Y
72 pla ; Restore low byte
73 stx tmp1 ; Save high byte of lhs