]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lshr.s
cfg/atari-xex.cfg: fix typo in comment
[cc65] / libsrc / runtime / lshr.s
1 ;
2 ; Ullrich von Bassewitz, 2004-06-30
3 ;
4 ; CC65 runtime: right shift support for unsigned longs
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         tosshreax
15         .import         popeax
16         .importzp       sreg, tmp1
17
18
19 tosshreax:
20         and     #$1F            ; Bring the shift count into a valid range
21         sta     tmp1            ; Save it
22
23         jsr     popeax          ; Get the left hand operand
24
25         ldy     tmp1            ; Get shift count
26         beq     L9              ; Bail out if shift count zero
27         stx     tmp1            ; Save byte 1
28
29 ; Do the actual shift. Faster solutions are possible but need a lot more code.
30
31 L2:     lsr     sreg+1
32         ror     sreg
33         ror     tmp1
34         ror     a
35         dey
36         bne     L2
37
38 ; Shift done
39
40         ldx     tmp1
41 L9:     rts
42
43
44
45
46
47
48