2 ; Ullrich von Bassewitz, 07.08.1998
4 ; CC65 runtime: helper stuff for mod/div/mul with signed ints
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.
10 .export popsargs, adjsres
12 .importzp sreg, tmp1, tmp2, ptr4
15 stx tmp1 ; Remember sign
18 jsr negax ; Negate accumulator
20 stx ptr4+1 ; Save right operand
23 stx tmp2 ; Remember sign
30 ; Calculate the sign of the result, that is sign(op1) * sign(op2)
34 sta tmp2 ; Save it across call
37 ; Adjust the result of a mod/div/mul operation
41 ; Check if we must adjust the sign
45 jmp negax ; Adjust sign