]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lshl.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / runtime / lshl.s
1 ;
2 ; Ullrich von Bassewitz, 2004-06-30
3 ;
4 ; CC65 runtime: left shift support for long and unsigned long
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         tosasleax, tosshleax
15         .import         popeax
16         .importzp       sreg, tmp1
17
18
19 tosshleax:
20 tosasleax:
21         and     #$1F            ; Bring the shift count into a valid range
22         sta     tmp1            ; Save it
23
24         jsr     popeax          ; Get the left hand operand
25
26         ldy     tmp1            ; Get shift count
27         beq     L9              ; Bail out if shift count zero
28         stx     tmp1            ; Save byte 1
29
30 ; Do the actual shift. Faster solutions are possible but need a lot more code.
31
32 L2:     asl     a
33         rol     tmp1
34         rol     sreg
35         rol     sreg+1
36         dey
37         bne     L2
38
39 ; Shift done
40
41         ldx     tmp1
42 L9:     rts
43
44