]> git.sur5r.net Git - cc65/blob - libsrc/runtime/mod.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / runtime / mod.s
1 ;
2 ; Ullrich von Bassewitz, 07.08.1998
3 ;
4 ; CC65 runtime: modulo operation for 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         tosmoda0, tosmodax
11         .import         popsargs, udiv16, negax
12         .importzp       ptr1, tmp1
13
14 tosmoda0:
15         ldx     #0
16 tosmodax:
17         jsr     popsargs        ; Get arguments from stack, adjust sign
18         jsr     udiv16          ; Do the division
19         lda     ptr1            ; Load low byte of result
20         ldx     ptr1+1          ; Load high byte of result
21
22 ; Adjust the sign of the result. tmp1 contains the high byte of the left
23 ; operand, tmp2 contains the high byte of the right operand. The sign of
24 ; the result of the modulo operation is the same as that of the left
25 ; operand
26
27         bit     tmp1
28         bpl     Pos             ; Jump if sign of result positive
29
30 ; Result is negative
31
32         jmp     negax           ; Adjust the sign
33
34 ; Result is positive
35
36 Pos:    rts
37