Compare commits

..

No commits in common. "8a823cf5117720c2933b703bc33d5d258259f70c" and "b5946dc3386243c8192d123eb28b1270d47b6bdb" have entirely different histories.

4 changed files with 197 additions and 1 deletions

82
inc/atoi_func.inc Normal file
View file

@ -0,0 +1,82 @@
%include "../inc/length_func.inc"
atoi_func:
mov r8, rdi
mov r8, text ;loop setup
xor r9, r9
_loopasd23:
mov r9b, [r8]
cmp r9, 0 ;check and see if we have reached the end of the string
jz _exitloopasd12
sub r9, 48
mov [r8], r9b
inc r8
jmp _loopasd23
_exitloopasd12:
call length_func
mov r8, rax
mov r11, rax
add r8, rdi
mov rcx, 1
_loop2asd12:
dec r8
mov al, [r8]
mul rcx
mov [r8], al
mov rax, rcx
mov r10, 10
mul r10
mov rcx, rax
cmp r8, rdi
je _exitloop2asd12
jmp _loop2asd12
_exitloop2asd12:
mov r8, rdi
mov r9, rdi
inc r9
_loop3asd12:
mov r11b, [r9]
mov r10b, [r8]
cmp r11, 0
jz _endasdasd23123
add r11, r10
mov [r9], r11b
mov [r8], r10b
inc r8
inc r9
jmp _loop3asd12
_endasdasd23123:
mov rax, [r8]
ret

18
inc/length_func.inc Normal file
View file

@ -0,0 +1,18 @@
length_func:
mov r10, rdi
xor r9, r9
_loop67865432:
mov r9, [rdi]
cmp r9, 0
jz _exitloop4323567
inc rdi
jmp _loop67865432
_exitloop4323567:
sub rdi, r10
mov rax, rdi
ret

@ -1 +1 @@
Subproject commit cf0d5fa5cb5d9ed232555d60a71e49203cc3c984 Subproject commit b5e1d53f010a65710144608018bd0274315988a5

96
monkie/strnum.asm Normal file
View file

@ -0,0 +1,96 @@
extern puts
%include "../inc/length_func.inc"
section .data
text db "42",0
section .text
global main
main:
sub rsp, 8
mov rdi, text
call length_func
mov r9, rax
mov r11, r9
mov r8, text
xor r10, r10
xor r11, r11
_loop:
mov r10, [r8]
cmp r10, 0
jz _exitloop ;if its zero we have reached the end of the string
mov r10, [r8]
sub r10, 48 ; change "0" into 0
mov [r8], r10
add r8, 1
jmp _loop
xor rcx, rcx
add rcx, 1
_exitloop:
cmp r9, r8
je _addvalues
mov r10, r9
mov rax, r10
mul rcx
mov r10, rax
mov [r9], r10
sub r9, 1
mov rdi, 10
mov rax, rcx
mul rdi
mov rcx, rax
jmp _exitloop
add r9, 1
_addvalues:
cmp r9, r11
je _end
mov r10, [r8]
mov r11, [r9]
add r11, r10
mov [r9], r11
add r8, 1
add r9, 1
jmp _addvalues
;this returns the r8 pointer
;mov rdi, text
;cld
;call puts ;this is the put s way of printing a string
_end:
add rsp, 8
ret
; mov rax, 60 ; exit
; mov edi, 1 ; error 1 dont need the exit anymore beacue libc or somthing
; syscall