]> git.sur5r.net Git - cc65/blob - libsrc/runtime/ldiv.s
goto.c warning fix for implicit truncation
[cc65] / libsrc / runtime / ldiv.s
1 ;
2 ; Ullrich von Bassewitz, 17.08.1998
3 ;
4 ; CC65 runtime: division for signed long ints
5 ;
6
7 ; When negating values, we will ignore the possibility here, that one of the
8 ; values if $80000000, in which case the negate will fail.
9
10         .export         tosdiv0ax, tosdiveax
11         .import         poplsargs, udiv32, negeax
12         .importzp       sreg, ptr1, tmp1, tmp2
13
14 tosdiv0ax:
15         ldy     #$00
16         sty     sreg
17         sty     sreg+1
18
19 tosdiveax:
20         jsr     poplsargs       ; Get arguments from stack, adjust sign
21         jsr     udiv32          ; Do the division, result is in (ptr1:sreg)
22         ldx     ptr1+1          ; Load byte 1 of result
23
24 ; Adjust the sign of the result
25
26         lda     tmp1            ; Get sign of left operand
27         eor     tmp2            ; Calculate sign of result
28         bpl     Pos             ; Jump if result positive
29
30 ; Result is negative
31
32         lda     ptr1            ; Load byte 0
33         jmp     negeax          ; Negate value
34
35 ; Result is positive
36
37 Pos:    lda     ptr1
38         rts
39
40