]> git.sur5r.net Git - cc65/blob - libsrc/runtime/div.s
Changed naming absvaludiv -> absvaludiv16.
[cc65] / libsrc / runtime / div.s
1 ;
2 ; Christian Krueger, 24-May-2018
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         absvaludiv16, negax
12         .importzp       sp, ptr1, tmp1
13
14 tosdiva0:
15         ldx     #0
16 tosdivax:
17         pha                         ; check if high-bytes indicate
18         txa                         ; different sign, so that we
19         ldy     #1                  ; negate the result after the operation
20         eor     (sp),y              ; eor with lhs high byte
21         sta     tmp1                ; save post negation indicator to tmp1
22         pla                         ; back to entry accu
23         jsr     absvaludiv16
24         ldx     ptr1+1
25         lda     ptr1
26         ldy     tmp1                ; fetch indicator
27         bmi     negate
28         rts
29 negate: jmp     negax