-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi_base.s
138 lines (119 loc) · 1.8 KB
/
ft_atoi_base.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;int ft_atoi_base(str-arg0-rdi, base-arg1-rsi)
section .note.GNU-stack
section .data
section .bss
section .text
global ft_atoi_base
ft_atoi_base:
xor rax, rax
xor r8, r8
xor r9, r9
xor r10, r10
mov r12, 1
jmp getlen
increase:
inc rax
cmp byte r8b, 0
je getlen
cmp byte r8b, 1
je check_base
cmp byte r8b, 2
je skip
cmp byte r8b, 3
je sign
cmp byte r8b, 4
je convert
getlen:
cmp byte [rsi + rax], 0
jne increase
jmp next
next:
cmp rax, 2
jl error
mov r9, rax ; save base length j
xor rax, rax
mov r8b, 1
jmp check_base
check_base:
cmp byte [rsi + rax], 0
je pre_skip
cmp byte [rsi + rax], 43 ; rax: i
je error
cmp byte [rsi + rax], 45
je error
cmp byte [rsi + rax], 32
jl error
mov rcx, rax ; rcx: k
jmp check_double
advance:
mov r8b, 1
cmp byte [rsi + rax], 0
jne increase
pre_skip:
xor rax, rax
mov r8b, 2
jmp skip
check_double:
cmp rcx, r9 ; k < j
jge advance
mov byte r10b, [rsi + rax]
cmp byte [rsi + rcx + 1], r10b
je error
inc rcx
jmp check_double
skip:
cmp byte [rdi + rax], 0
je error
cmp byte [rdi + rax], 9
jge check_upper
jmp sign
check_upper:
cmp byte [rdi + rax], 13
jle increase
cmp byte [rdi + rax], 32
jne prep_sign
jmp increase
prep_sign:
mov r8b, 3
jmp sign
sign:
cmp byte [rdi + rax], 0
je error
cmp byte [rdi + rax], 43
jne check_minus
jmp increase
check_minus:
cmp byte [rdi + rax], 45
je minus
jmp prep_convert
prep_convert:
xor r11, r11
mov r8b, 4
jmp convert
minus:
neg r12
jmp increase
convert:
cmp byte [rdi + rax], 0
je finish
mov rcx, -1
jmp in_base
compute:
imul r11, r9
add r11, rcx
jmp increase
in_base:
inc rcx
cmp byte [rsi + rcx], 0
je finish
mov byte r10b, [rsi + rcx]
cmp byte [rdi + rax], r10b
jne in_base
jmp compute
finish:
imul r11, r12
mov rax, r11
ret
error:
xor rax, rax
ret