]> git.sur5r.net Git - cc65/blob - libsrc/runtime/shl.s
Package additional linker configs for the apple2enh
[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
15         .import         popax
16         .importzp       tmp1
17
18 tosshlax:
19 tosaslax:
20         and     #$0F            ; Bring the shift count into a valid range
21         sta     tmp1            ; Save it
22
23         jsr     popax           ; Get the left hand operand
24
25         ldy     tmp1            ; Get shift count
26         beq     L9              ; Bail out if shift count zero
27
28         cpy     #8              ; Shift count 8 or greater?
29         bcc     L3              ; Jump if not
30
31 ; Shift count is greater 7. The carry is set when we enter here.
32
33         tax
34         tya
35         sbc     #8
36         tay
37         txa
38         jmp     L2
39 L1:     asl     a
40 L2:     dey
41         bpl     L1
42         tax
43         lda     #$00
44         rts
45
46 ; Shift count is less than 8.
47
48 L3:     stx     tmp1            ; Save high byte of lhs
49 L4:     asl     a
50         rol     tmp1
51         dey
52         bne     L4
53
54 ; Done with shift
55
56         ldx     tmp1
57 L9:     rts
58