]> git.sur5r.net Git - cc65/blob - libsrc/runtime/lshelp.s
Merge pull request #829 from inexorabletash/string-escapes
[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
11         .import         getlop
12         .importzp       sreg, tmp1, tmp2, ptr1, ptr3, ptr4
13
14 poplsargs:
15         jsr     getlop          ; Get the operands
16
17 ; Remember the signs of the operands (that is, the high bytes) in tmp1 and
18 ; tmp2. Make both operands positive.
19
20         lda     sreg+1          ; Is the left operand negative?
21         sta     tmp1            ; Remember the sign for later
22         bpl     L1              ; Jump if not
23
24         clc                     ; Make it positive
25         lda     ptr1
26         eor     #$FF
27         adc     #$01
28         sta     ptr1
29         lda     ptr1+1
30         eor     #$FF
31         adc     #$00
32         sta     ptr1+1
33         lda     sreg
34         eor     #$FF
35         adc     #$00
36         sta     sreg
37         lda     sreg+1
38         eor     #$FF
39         adc     #$00
40         sta     sreg+1
41
42 L1:     lda     ptr4+1          ; Is the right operand nagative?
43         sta     tmp2            ; Remember the sign for later
44         bpl     L2              ; Jump if not
45
46         clc                     ; Make it positive
47         lda     ptr3
48         eor     #$FF
49         adc     #$01
50         sta     ptr3
51         lda     ptr3+1
52         eor     #$FF
53         adc     #$00
54         sta     ptr3+1
55         lda     ptr4
56         eor     #$FF
57         adc     #$00
58         sta     ptr4
59         lda     ptr4+1
60         eor     #$FF
61         adc     #$00
62         sta     ptr4+1
63
64 L2:     rts
65