]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lmod.s
Added an IRQ vector
[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         tosmodeax
11         .import         poplsargs, udiv32, negeax
12         .importzp       sreg, ptr1, ptr2, tmp1, tmp3, tmp4
13
14 tosmodeax:
15         jsr     poplsargs       ; Get arguments from stack, adjust sign
16         jsr     udiv32          ; Do the division, remainder is in (ptr2:tmp3:tmp4)
17
18 ; Load the result
19
20         lda     ptr2
21         ldx     ptr2+1
22         ldy     tmp3
23         sty     sreg
24         ldy     tmp4
25         sty     sreg+1
26
27 ; Check the sign of the result. It is the sign of the left operand.
28
29         bit     tmp1            ; Check sign of left operand
30         bpl     Pos             ; Jump if result is positive
31
32 ; Result is negative
33
34         jmp     negeax          ; Negate result
35
36 ; Result is positive
37
38 Pos:    rts                     ; Done
39