]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lshl.s
Added dump of the file list
[cc65] / libsrc / runtime / lshl.s
1 ;
2 ; Ullrich von Bassewitz, 20.09.1998
3 ;
4 ; CC65 runtime: left shift support for longs
5 ;
6
7
8         .export         tosasleax, tosshleax
9         .import         addysp1
10         .importzp       sp, sreg, ptr1, ptr2
11
12
13 tosshleax:
14 tosasleax:
15
16 ; Get the lhs from stack into ptr1/ptr2
17
18         pha
19         ldy     #0
20         lda     (sp),y
21         sta     ptr1
22         iny
23         lda     (sp),y
24         sta     ptr1+1
25         iny
26         lda     (sp),y
27         sta     ptr2
28         iny
29         lda     (sp),y
30         sta     ptr2+1
31         pla
32         jsr     addysp1
33
34 ; Check for shift overflow or zero shift
35
36         tay                     ; Low byte of shift count into y
37         txa                     ; Get byte 2
38         ora     sreg
39         ora     sreg+1          ; Check high 24 bit
40         bne     @L6             ; Shift count too large
41         cpy     #32
42         bcs     @L6
43
44         cpy     #0              ; Shift count zero?
45         beq     @L5
46
47 ; We must shift. Shift by multiples of eight if possible
48
49         tya
50 @L1:    cmp     #8
51         bcc     @L3
52         sbc     #8
53         ldx     ptr2
54         stx     ptr2+1
55         ldx     ptr1+1
56         stx     ptr2
57         ldx     ptr1
58         stx     ptr1+1
59         ldx     #0
60         stx     ptr1
61         beq     @L1
62
63 ; Shift count is now less than eight. Do a real shift.
64
65 @L3:    tay                     ; Shift count to Y
66         lda     ptr1            ; Get one byte into A for speed
67         cpy     #0
68         beq     @L4a            ; Jump if done
69 @L4:    asl     a
70         rol     ptr1+1
71         rol     ptr2
72         rol     ptr2+1
73         dey
74         bne     @L4
75
76 ; Put the result in place
77
78 @L4a:   ldx     ptr2
79         stx     sreg
80         ldx     ptr2+1
81         stx     sreg+1
82         ldx     ptr1+1
83 @L5:    rts
84
85 ; Jump here if shift count overflow
86
87 @L6:    lda     #0
88         sta     sreg+1
89         sta     sreg
90         tax
91         rts
92
93
94
95