Skip to content

Commit b452fd0

Browse files
committed
optimized atexit/on_exit
1 parent e3c6850 commit b452fd0

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

src/libc/atexit.src

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ _on_exit:
1111
ld hl, 3 * 3
1212
push hl
1313
call _malloc
14-
pop bc
14+
pop de
1515
ex de, hl
1616
scf
1717
sbc hl, hl
@@ -21,23 +21,19 @@ _on_exit:
2121
ex de, hl
2222
ld (__atexit_functions), hl
2323
ld (hl), de
24-
pop iy ; return address
25-
inc hl
26-
inc hl
27-
inc hl
28-
pop bc ; func pointer
29-
ld (hl), bc
30-
inc hl
31-
inc hl
32-
inc hl
33-
pop bc ; arg pointer (on_exit)
34-
ld (hl), bc
35-
push bc
36-
push bc
24+
ld de, 3
25+
add hl, de
26+
ex de, hl
27+
add hl, sp ; clears carry
28+
ld bc, 6
29+
; (SP + 3) = func pointer
30+
; (SP + 6) = arg pointer (on_exit)
31+
; HL = SP + 3
32+
; DE = (__atexit_functions) + 3
33+
ldir
3734
; return zero on success
38-
or a, a
3935
sbc hl, hl
40-
jp (iy)
36+
ret
4137

4238
.section .bss
4339
.global __atexit_functions

0 commit comments

Comments
 (0)