]> git.sur5r.net Git - cc65/blob - libsrc/runtime/leave.s
Merge pull request #281 from polluks/sp65
[cc65] / libsrc / runtime / leave.s
1 ;  
2 ; Ullrich von Bassewitz, 06.08.1998
3 ;
4 ; CC65 runtime: function epilogue
5 ;
6
7 ; exit a function.  pop stack and rts. The function comes in different
8 ; flavours that provide default values for the return val, or drop a local
9 ; stack frame with size in y.
10
11         .export         leave00, leave0, leavey00, leavey0, leavey
12         .export         leave
13         .import         addysp
14         .importzp       sp
15
16 leave00:
17         lda     #0
18 leave0: ldx     #0
19         beq     leave
20
21 leavey00:
22         lda     #0              ; "return 0"
23 leavey0:
24         ldx     #0              ; return < 256
25 leavey:
26         jsr     addysp          ; drop stack frame
27 leave:  pha                     ; save A a sec
28         ldy     #0
29         lda     (sp),y          ; that's the pushed arg size
30         sec                     ; Count the byte, the count's stored in
31         adc     sp
32         sta     sp
33         bcc     L1
34         inc     sp+1
35 L1:     pla                     ; Get return value back
36         rts
37