]> git.sur5r.net Git - cc65/blob - libsrc/runtime/add.s
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / libsrc / runtime / add.s
1 ;
2 ; Ullrich von Bassewitz, 05.08.1998
3 ;
4 ; CC65 runtime: add ints
5 ;
6
7 ; Make this as fast as possible, even if it needs more space since it's
8 ; called a lot!
9
10         .export         tosadda0, tosaddax
11         .importzp       sp, tmp1
12
13 tosadda0:
14         ldx     #0
15 tosaddax:
16         ldy     #0
17         clc
18         adc     (sp),y          ; lo byte
19         sta     tmp1            ; save it
20         txa
21         iny
22         adc     (sp),y          ; hi byte
23         tax
24         clc
25         lda     sp
26         adc     #2
27         sta     sp
28         bcc     L1
29         inc     sp+1
30 L1:     txa                     ; Test high byte
31         bmi     L2
32         bne     L3
33         lda     tmp1            ; Get low byte
34         rts
35
36 ; Value is negative
37
38 L2:     lda     tmp1            ; Get low byte
39         ldy     #$FF            ; Force negative
40         rts
41
42 ; Value is positive != 0
43
44 L3:     lda     tmp1            ; Get low byte
45         ldy     #1
46         rts
47