]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lasr.s
Free 2 bytes again.
[cc65] / libsrc / runtime / lasr.s
1 ;
2 ; Ullrich von Bassewitz, 2004-06-30
3 ;
4 ; CC65 runtime: right shift support for longs
5 ;
6 ; Note: The standard declares a shift count that is negative or >= the
7 ; bitcount of the shifted type for undefined behaviour.
8 ;
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!
11 ;
12
13
14         .export         tosasreax
15         .import         popeax
16         .importzp       sreg, tmp1
17
18
19 tosasreax:
20         and     #$1F            ; Bring the shift count into a valid range
21         sta     tmp1            ; Save it
22
23         jsr     popeax          ; Get the left hand operand
24
25         ldy     tmp1            ; Get shift count
26         beq     L9              ; Bail out if shift count zero
27         stx     tmp1            ; Save byte 1
28         ldx     sreg+1          ; Load byte 3
29
30 ; Do the actual shift. Faster solutions are possible but need a lot more code.
31
32 L2:     cpx     #$80            ; Copy bit 31 into the carry
33         ror     sreg+1
34         ror     sreg
35         ror     tmp1
36         ror     a
37         dey
38         bne     L2
39
40 ; Shift done
41
42         ldx     tmp1
43 L9:     rts
44