2 ; Ullrich von Bassewitz, 07.08.1998
4 ; CC65 runtime: modulo operation for signed ints
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values is $8000, in which case the negate will fail.
10 .export tosmoda0, tosmodax
11 .import popsargsudiv16, negax
17 jsr popsargsudiv16 ; Get arguments from stack, adjust sign
19 lda sreg ; Load low byte of result
20 ldx sreg+1 ; Load high byte of result
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
28 bpl Pos ; Jump if sign of result positive
32 jmp negax ; Adjust the sign