Skip to content

Commit 80eb0d3

Browse files
committed
implemented strto(u)ll in assembly
1 parent b7949c3 commit 80eb0d3

File tree

5 files changed

+390
-307
lines changed

5 files changed

+390
-307
lines changed

src/libc/atoll.src

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,20 @@
11
assume adl=1
22

33
section .text
4-
54
public _atoll
6-
75
_atoll:
8-
push ix
9-
ld ix, -3
10-
add ix, sp
11-
ld hl, (ix + 9)
12-
; inlined isspace
13-
.whitespace_loop:
14-
ld a, (hl)
15-
inc hl
16-
cp a, 32
17-
jr z, .whitespace_loop
18-
sub a, 9
19-
add a, -5
20-
jr nc, .whitespace_loop
21-
22-
; A = (HL - 1) - 9 + -5
23-
; A = (HL - 1) - 14
24-
xor a, '-' - 14
25-
push af
26-
jr z, .minus_sign
27-
xor a, ('+' - 14) xor ('-' - 14)
28-
jr z, .plus_sign
29-
dec hl
30-
.plus_sign:
31-
.minus_sign:
32-
; carry is cleared
33-
push hl
34-
pop iy
35-
sbc hl, hl
36-
ex de, hl
37-
sbc hl, hl
38-
ld b, l
39-
ld c, l
6+
pop bc
7+
ex (sp),hl
8+
push bc
9+
ld bc,10
10+
push bc
11+
ld c,b
12+
push bc
4013
push hl
41-
push hl
42-
push hl
43-
; IY = start of the digits
44-
; BC:UDE:UHL = 0
45-
; (ix - 9) = [0, 10]
46-
jr .start
47-
.loop:
48-
; loop : 27F + 1R + 8W + 1
49-
; lladd : ?
50-
; llmulu: ?
51-
; total : a lot per digit
52-
ld (ix - 9), 10
53-
call __llmulu ; BC:UDE:UHL *= 10
54-
ld (ix - 9), a
55-
call __lladd
56-
inc iy ; next digit
57-
.start:
58-
ld a, (iy)
59-
sub a, 48
60-
cp a, 10
61-
jr c, .loop
62-
.finish:
63-
ld sp, ix
14+
call _strtoll
15+
pop af
16+
pop af
6417
pop af
65-
; carry is cleared
66-
pop ix
67-
ret nz ; A != '-' positive
68-
; A == '-' negative
69-
jp __llneg
18+
ret
7019

71-
extern __llneg
72-
extern __lladd
73-
extern __llmulu
20+
extern _strtoll

src/libc/strtoll.c

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)