]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lmod.s
Do not try to dump an expression that has errors (circular references in this
[cc65] / libsrc / runtime / lmod.s
1 ;
2 ; Ullrich von Bassewitz, 07.08.1998
3 ;
4 ; CC65 runtime: modulo operation for long signed ints
5 ;
6
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values if $8000, in which case the negate will fail.
9
10         .export         tosmod0ax, tosmodeax
11         .import         poplsargs, udiv32, negeax
12         .importzp       sreg, ptr1, ptr2, tmp1, tmp3, tmp4
13
14 tosmod0ax:
15         ldy     #$00
16         sty     sreg
17         sty     sreg+1
18
19 tosmodeax:                         
20         jsr     poplsargs       ; Get arguments from stack, adjust sign
21         jsr     udiv32          ; Do the division, remainder is in (ptr2:tmp3:tmp4)
22
23 ; Load the result
24
25         lda     ptr2
26         ldx     ptr2+1
27         ldy     tmp3
28         sty     sreg
29         ldy     tmp4
30         sty     sreg+1
31
32 ; Check the sign of the result. It is the sign of the left operand.
33
34         bit     tmp1            ; Check sign of left operand
35         bpl     Pos             ; Jump if result is positive
36
37 ; Result is negative
38
39         jmp     negeax          ; Negate result
40
41 ; Result is positive
42
43 Pos:    rts                     ; Done
44