]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lumod.s
few 6502 and some 65SC02 optimizations
[cc65] / libsrc / runtime / lumod.s
1 ;
2 ; Ullrich von Bassewitz, 27.09.1998
3 ; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
4 ;
5 ; CC65 runtime: modulo operation for long unsigned ints
6 ;
7
8         .export         tosumod0ax, tosumodeax
9         .import         getlop, udiv32
10         .importzp       sreg, tmp3, tmp4, ptr2
11
12         .macpack        cpu
13
14 tosumod0ax:                          
15 .if (.cpu .bitand ::CPU_ISET_65SC02)
16         stz     sreg
17         stz     sreg+1
18 .else
19         ldy     #$00
20         sty     sreg
21         sty     sreg+1
22 .endif
23
24 tosumodeax:
25         jsr     getlop          ; Get the paramameters
26         jsr     udiv32          ; Do the division
27         lda     tmp3            ; Remainder is in ptr2:tmp3:tmp4
28         sta     sreg
29         lda     tmp4
30         sta     sreg+1
31         lda     ptr2
32         ldx     ptr2+1
33         rts
34