]> git.sur5r.net Git - cc65/blob - libsrc/runtime/div.s
Made the code that logs indirect-goto referals be a little more efficient.
[cc65] / libsrc / runtime / div.s
1 ;
2 ; Ullrich von Bassewitz, 07.08.1998
3 ;
4 ; CC65 runtime: division for signed ints
5 ;
6
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.
9
10         .export         tosdiva0, tosdivax
11         .import         popsargsudiv16, negax
12         .importzp       ptr1, tmp1, tmp2
13
14 tosdiva0:
15         ldx     #0
16 tosdivax:
17         jsr     popsargsudiv16  ; Get arguments from stack, adjust sign
18                                 ; and do the division
19         ldx     ptr1+1          ; Load high byte of result
20
21 ; Adjust the sign of the result. tmp1 contains the high byte of the left
22 ; operand, tmp2 contains the high byte of the right operand.
23
24         lda     tmp1
25         eor     tmp2
26         bpl     Pos             ; Jump if sign of result positive
27
28 ; Result is negative
29
30         lda     ptr1            ; Load low byte of result
31         jmp     negax           ; Adjust the sign
32
33 ; Result is positive
34
35 Pos:    lda     ptr1            ; Load low byte of result
36         rts
37