]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lmod.s
Fixed a bug
[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 with the exception of the low byte
19
20         ldx     ptr2+1
21         ldy     tmp3
22         sty     sreg
23         ldy     tmp4
24         sty     sreg+1
25
26 ; Check the sign of the result. It is the sign of the left operand.
27
28         lda     tmp1            ; Check sign of left operand
29         bpl     Pos             ; Jump if result is positive
30
31 ; Result is negative
32
33         lda     ptr2            ; Load byte 0 of result
34         jmp     negeax          ; Negate result
35
36 ; Result is positive
37
38 Pos:    lda     ptr2            ; Load byte 0 of result
39         rts                     ; Done
40