]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lshelp.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / runtime / lshelp.s
1 ;
2 ; Ullrich von Bassewitz, 13.08.1998
3 ;
4 ; CC65 runtime: helper stuff for mod/div/mul with long signed 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         poplsargs, adjlsres
11         .import         getlop, negeax
12         .importzp       sreg, tmp1, ptr1, ptr3, ptr4
13
14 poplsargs:
15         jsr     getlop          ; Get the operands
16
17 ; Calculate the sign of the result, that is sign(op1) * sign(op2) and
18 ; remember it.
19
20         lda     sreg+1
21         eor     ptr4+1
22         sta     tmp1            ; Save it across call
23
24 ; Make both operands positive
25
26         lda     sreg+1          ; Is the operand negative?
27         bpl     L1              ; Jump if not
28
29         clc                     ; Make it positive
30         lda     ptr1
31         eor     #$FF
32         adc     #$01
33         sta     ptr1
34         lda     ptr1+1
35         eor     #$FF
36         adc     #$00
37         sta     ptr1+1
38         lda     sreg
39         eor     #$FF
40         adc     #$00
41         sta     sreg
42         lda     sreg+1
43         eor     #$FF
44         adc     #$00
45         sta     sreg+1
46
47 L1:     lda     ptr4+1          ; Is the operand nagative?
48         bpl     L2              ; Jump if not
49
50         clc                     ; Make it positive
51         lda     ptr3
52         eor     #$FF
53         adc     #$01
54         sta     ptr3
55         lda     ptr3+1
56         eor     #$FF
57         adc     #$00
58         sta     ptr3+1
59         lda     ptr4
60         eor     #$FF
61         adc     #$00
62         sta     ptr4
63         lda     ptr4+1
64         eor     #$FF
65         adc     #$00
66         sta     ptr4+1
67
68 L2:     rts
69
70 ; Adjust the result of a mod/div/mul operation
71
72 adjlsres:
73         ldy     tmp1            ; Check if we must adjust the sign
74         bpl     L2
75         jmp     negeax          ; Netage value
76