]> git.sur5r.net Git - cc65/blob - libsrc/runtime/shl.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / runtime / shl.s
1 ;
2 ; Ullrich von Bassewitz, 05.08.1998
3 ;
4 ; CC65 runtime: left shift support for ints
5 ;
6
7         .export         tosasla0, tosaslax, tosshla0, tosshlax
8         .import         popsreg, return0
9         .importzp       sreg
10
11 tosshla0:
12 tosasla0:
13         ldx     #0
14 tosshlax:
15 tosaslax:
16         jsr     popsreg         ; get TOS into sreg
17         cpx     #0
18         bne     TooLarge
19         cmp     #16
20         bcs     TooLarge
21
22         cmp     #8              ; Shift count greater 8?
23         beq     L3              ; Jump if exactly 8
24         bcc     L1              ; Jump if no
25
26 ; Shift count is greater 8. Do the first 8 bits the fast way
27
28         ldy     sreg
29         sty     sreg+1
30         stx     sreg            ; Low byte = 0
31         sec
32         sbc     #8
33
34 ; Shift count less than 8 if we come here
35
36 L1:     tay                     ; Shift count --> Y
37         beq     Zero            ; Done if shift count zero
38
39         lda     sreg            ; get low byte for faster shift
40
41 ; Do the actual shift
42
43 L2:     asl     a
44         rol     sreg+1
45         dey
46         bne     L2
47
48 ; Done with shift
49
50         ldx     sreg+1
51         rts
52
53 ; Shift count == 8
54
55 L3:     txa                     ; X == 0, now A == 0
56         ldx     sreg
57         rts
58
59 ; Shift count was zero
60
61 Zero:   lda     sreg
62         ldx     sreg+1
63         rts
64
65 ; Shift count too large, result is zero
66
67 TooLarge:
68         jmp     return0
69