]> git.sur5r.net Git - cc65/blob - libsrc/runtime/pushax.s
077c52ca8c4e1f933287795c1a12a827e1c97fd1
[cc65] / libsrc / runtime / pushax.s
1 ;
2 ; Ullrich von Bassewitz, 26.10.2000
3 ;
4 ; CC65 runtime: Push value in a/x onto the stack
5 ;
6
7         .export         push0, pusha0, pushax
8         .importzp       sp
9
10 push0:  lda     #0
11 pusha0: ldx     #0
12
13 ; This function is used *a lot*, so don't call any subroutines here.
14 ; Beware: The value in ax must not be changed by this function!
15 ; Beware^2: The optimizer knows about the value of Y after the function
16 ;           returns!
17
18 pushax: ldy     sp
19         beq     @L1
20         dey
21         beq     @L2
22         dey
23 @L0:    sty     sp
24         ldy     #0              ; get index
25         sta     (sp),y          ; store lo byte
26         pha                     ; save it
27         txa                     ; get hi byte
28         iny                     ; bump idx
29         sta     (sp),y          ; store hi byte
30         pla                     ; get A back
31         rts                     ; done
32
33 @L1:    dey
34 @L2:    dey
35         dec     sp+1
36         jmp     @L0
37
38