]> git.sur5r.net Git - cc65/blob - libsrc/runtime/shl.s
Made the code that logs indirect-goto referals be a little more efficient.
[cc65] / libsrc / runtime / shl.s
1 ;
2 ; Ullrich von Bassewitz, 1998-08-05, 2004-06-25
3 ;
4 ; CC65 runtime: left shift support for ints and unsigneds
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          tosaslax, tosshlax, aslaxy, shlaxy
15         .import          popax
16         .importzp        tmp1
17
18         .macpack        cpu
19
20 tosshlax:
21 tosaslax:
22         sta     tmp1            ; Save shift count
23         jsr     popax           ; Get the left hand operand
24         ldy     tmp1            ; Get shift count
25
26 ; Run into shlaxy
27
28 shlaxy:
29 aslaxy:
30         pha
31         tya
32         and     #$0F
33         beq     L2              ; Nothing to shift
34         sec
35         sbc     #8              ; Shift count 8 or greater?
36         beq     L3              ; Jump if exactly 8
37         bcc     L4              ; Jump if less than 8
38
39 ; Shift count is greater than 8.
40
41         tay                     ; Shift count into Y
42         pla                     ; Get low byte
43
44 L1:     asl     a
45         dey
46         bne     L1
47         tax
48         tya                     ; A = 0
49         rts
50
51 ; Shift count is zero
52
53 L2:     pla
54         rts
55
56 ; Shift count is exactly 8
57
58 .if (.cpu .bitand CPU_ISET_65SC02)
59 L3:     plx                     ; Low byte from stack into X
60         rts                     ; A is already zero
61 .else
62 L3:     pla                     ; Low byte from stack ...
63         tax                     ; ... into X
64         lda     #$00            ; Clear low byte
65         rts
66 .endif
67
68 ; Shift count is less than 8
69
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
74 L5:     asl     a
75         rol     tmp1
76         dey
77         bne     L5
78
79 ; Done with shift
80
81         ldx     tmp1
82 L9:     rts
83