File: lshr.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (48 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;
; Ullrich von Bassewitz, 2004-06-30
;
; CC65 runtime: right shift support for unsigned longs
;
; Note: The standard declares a shift count that is negative or >= the
; bitcount of the shifted type for undefined behaviour.
;
; Note^2: The compiler knowns about the register/zero page usage of this
; function, so you need to change the compiler source if you change it!
;


        .export         tosshreax
        .import         popeax
        .importzp       sreg, tmp1


tosshreax:
        and     #$1F            ; Bring the shift count into a valid range
        sta     tmp1            ; Save it

        jsr     popeax          ; Get the left hand operand

        ldy     tmp1            ; Get shift count
        beq     L9              ; Bail out if shift count zero
        stx     tmp1            ; Save byte 1

; Do the actual shift. Faster solutions are possible but need a lot more code.

L2:     lsr     sreg+1
        ror     sreg
        ror     tmp1
        ror     a
        dey
        bne     L2

; Shift done

        ldx     tmp1
L9:     rts