]> git.sur5r.net Git - cc65/blob - libsrc/runtime/add.s
Merge pull request #740 from laubzega/master
[cc65] / libsrc / runtime / add.s
1 ;
2 ; Ullrich von Bassewitz, 05.08.1998
3 ; Christian Krueger, 11-Mar-2017, spend two bytes for one cycle, improved 65SC02 optimization
4 ;
5 ; CC65 runtime: add ints
6 ;
7
8 ; Make this as fast as possible, even if it needs more space since it's
9 ; called a lot!
10
11         .export         tosadda0, tosaddax
12         .importzp       sp, tmp1
13
14         .macpack        cpu
15
16 tosadda0:
17         ldx     #0
18 tosaddax:
19         clc                     ; (2)
20
21 .if (.cpu .bitand ::CPU_ISET_65SC02)
22
23         adc     (sp)            ; (7)
24         tay                     ; (9)
25         inc     sp              ; (14)
26         bne     hiadd           ; (17)
27         inc     sp+1            ; (-1+5)
28 hiadd:  txa                     ; (19)
29         adc     (sp)            ; (24)
30         tax                     ; (26)
31         inc     sp              ; (31)
32         bne     done            ; (34)
33         inc     sp+1            ; (-1+5)
34 done:   tya                     ; (36)
35
36 .else        
37
38         ldy     #0              ; (4)
39         adc     (sp),y          ; (9) lo byte
40         iny                     ; (11)
41         sta     tmp1            ; (14) save it
42         txa                     ; (16) 
43         adc     (sp),y          ; (21) hi byte
44         tax                     ; (23)
45         clc                     ; (25)
46         lda     sp              ; (28)
47         adc     #2              ; (30)
48         sta     sp              ; (33)
49         bcc     L1              ; (36)
50         inc     sp+1            ; (-1+5)
51 L1:     lda     tmp1            ; (39) restore low byte
52
53 .endif
54         rts                     ; (6502: 45 cycles, 26 bytes <-> 65SC02: 42 cycles, 22 bytes )