aboutsummaryrefslogtreecommitdiff
path: root/ft_atoi_base.s
diff options
context:
space:
mode:
Diffstat (limited to 'ft_atoi_base.s')
-rw-r--r--ft_atoi_base.s83
1 files changed, 42 insertions, 41 deletions
diff --git a/ft_atoi_base.s b/ft_atoi_base.s
index 6245765..e51487c 100644
--- a/ft_atoi_base.s
+++ b/ft_atoi_base.s
@@ -1,25 +1,26 @@
-# **************************************************************************** #
-# #
-# ::: :::::::: #
-# ft_atoi_base.s :+: :+: :+: #
-# +:+ +:+ +:+ #
-# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
-# +#+#+#+#+#+ +#+ #
-# Created: 2019/11/22 03:59:15 by cacharle #+# #+# #
-# Updated: 2019/11/22 21:18:08 by cacharle ### ########.fr #
-# #
-# **************************************************************************** #
+; **************************************************************************** ;
+; ;
+; ::: :::::::: ;
+; ft_atoi_base.s :+: :+: :+: ;
+; +:+ +:+ +:+ ;
+; By: cacharle <marvin@42.fr> +;+ +:+ +;+ ;
+; +;+;+;+;+;+ +;+ ;
+; Created: 2019/11/22 03:59:15 by cacharle ;+; ;+; ;
+; Updated: 2019/11/22 21:18:08 by cacharle ;;; ;;;;;;;;.fr ;
+; ;
+; **************************************************************************** ;
-.globl _ft_atoi_base
-.globl _check_base
+extern _ft_strlen
-# int ft_atoi_base(const char*, const char*);
+global _ft_atoi_base
+
+; int ft_atoi_base(const char*, const char*);
_ft_atoi_base:
- push rbp # save previous stackframe
- mov rbp, rsp # create new one
+ push rbp ; save previous stackframe
+ mov rbp, rsp ; create new one
- mov rbx, rdi # rbx = str
- mov rcx, rsi # rcx = base
+ mov rbx, rdi ; rbx = str
+ mov rcx, rsi ; rcx = base
mov rdi, rcx
call _check_base
@@ -28,11 +29,11 @@ _ft_atoi_base:
mov rdi, rcx
call _ft_strlen
- #mov r8, rax # r8 = radix
- #mov rax, r8
+ ;mov r8, rax ; r8 = radix
+ ;mov rax, r8
- xor rdx, rdx # rdx = 0
- FT_ATOI_BASE_SPACE_LOOP: # remove spaces
+ xor rdx, rdx ; rdx = 0
+ FT_ATOI_BASE_SPACE_LOOP: ; remove spaces
mov rdi, [rbx]
call ft_isspace
cmp rax, 1
@@ -41,18 +42,18 @@ _ft_atoi_base:
jmp FT_ATOI_BASE_SPACE_LOOP
FT_ATOI_BASE_SPACE_LOOP_END:
- xor rax, rax # rax = 0
- xor rdx, rdx # rdx = 0
+ xor rax, rax ; rax = 0
+ xor rdx, rdx ; rdx = 0
FT_ATOI_BASE_LOOP:
- cmp byte ptr [rbx], 30h # while isdigit
- jl FT_ATOI_BASE_END # if *rbx < '0' jmp end
- cmp byte ptr [rbx], 39h
- ja FT_ATOI_BASE_END # if *rbx > '9' jmp end
+ cmp byte [rbx], 30h ; while isdigit
+ jl FT_ATOI_BASE_END ; if *rbx < '0' jmp end
+ cmp byte [rbx], 39h
+ ja FT_ATOI_BASE_END ; if *rbx > '9' jmp end
- imul eax, 10 # eax *= 10, shift previous digits
- mov dl, byte ptr [rbx]
- and dl, 0x0F # char to digit
- add eax, edx # insert as first digit
+ imul eax, 10 ; eax *= 10, shift previous digits
+ mov dl, byte [rbx]
+ and dl, 0x0F ; char to digit
+ add eax, edx ; insert as first digit
inc rbx
jmp FT_ATOI_BASE_LOOP
FT_ATOI_BASE_END:
@@ -63,9 +64,9 @@ _base_pos:
mov rcx, rsi
xor rax, rax
BASE_POS_LOOP:
- cmp byte ptr [rdi + rax], 0
+ cmp byte [rdi + rax], 0
je BASE_POS_NOT_FOUND
- cmp cl, byte ptr [rdi + rax]
+ cmp cl, byte [rdi + rax]
je BASE_POS_FOUND
inc eax
jmp BASE_POS_LOOP
@@ -78,23 +79,23 @@ _check_base:
push rbx
mov rbx, rsp
- mov rbx, rdi # rbx = str
+ mov rbx, rdi ; rbx = str
- call _ft_strlen # f strlen(rbx) < 2
+ call _ft_strlen ; f strlen(rbx) < 2
cmp eax, 2
jl CHECK_BASE_ERROR
CHECK_BASE_LOOP:
- cmp byte ptr [rbx], 2bh # *rbx == '-' || *rbx == '+'
+ cmp byte [rbx], 2bh ; *rbx == '-' || *rbx == '+'
je CHECK_BASE_ERROR
- cmp byte ptr [rbx], 2dh
+ cmp byte [rbx], 2dh
je CHECK_BASE_ERROR
call ft_isspace
cmp rax, 1
je CHECK_BASE_ERROR
inc rbx
- cmp byte ptr [rbx], 0h
+ cmp byte [rbx], 0h
jne CHECK_BASE_LOOP
mov rax, 1
pop rbx
@@ -105,9 +106,9 @@ _check_base:
ret
ft_isspace:
- cmp byte ptr [rdi], 20h # if space jump next
+ cmp byte [rdi], 20h ; if space jump next
je ISSPACE_TRUE_END
- mov dl, byte ptr [rdi] # if \t\n\r\v\f jump next
+ mov dl, byte [rdi] ; if \t\n\r\v\f jump next
sub dl, 9h
cmp dl, 5h
jl ISSPACE_TRUE_END