]> git.sur5r.net Git - cc65/blob - libsrc/runtime/laddeq.s
2632ec90940ea932742401718d0f3139fc99ce0f
[cc65] / libsrc / runtime / laddeq.s
1 ;
2 ; Ullrich von Bassewitz, 07.04.2000
3 ;
4 ; CC65 runtime: += operator
5 ;
6 ; On entry, the low byte of the address of the variable to increment is
7 ; in ptr1, the high byte is in Y, and the increment is in eax.
8 ;
9
10         .export         laddeq1, laddeqa, laddeq
11         .importzp       sreg, ptr1, tmp1
12
13
14 laddeq1:
15         lda     #$01
16
17 laddeqa:
18         ldx     #$00
19         stx     sreg
20         stx     sreg+1
21
22 laddeq: sty     ptr1+1                  ; Store high byte of address
23         ldy     #$00                    ; Address low byte
24         clc
25
26         adc     (ptr1),y
27         sta     (ptr1),y
28         pha                             ; Save byte 0 of result for later
29
30         iny                             ; Address byte 1
31         txa
32         adc     (ptr1),y                ; Load byte 1
33         sta     (ptr1),y
34         tax
35
36         iny                             ; Address byte 2
37         lda     sreg
38         adc     (ptr1),y
39         sta     (ptr1),y
40         sta     sreg
41
42         iny                             ; Address byte 3
43         lda     sreg+1
44         adc     (ptr1),y
45         sta     (ptr1),y
46         sta     sreg+1
47
48         pla                             ; Retrieve byte 0 of result
49
50         rts                             ; Done
51
52
53