did some things idk

This commit is contained in:
zombie maniac 2021-10-02 18:48:39 -04:00
parent d0cbf26c4a
commit e1c8d1f740
5 changed files with 124 additions and 19 deletions

View file

@ -21,4 +21,4 @@ add_executable(length length.asm)
add_executable(yes yes.asm) add_executable(yes yes.asm)
add_executable(case case.asm) add_executable(case case.asm)
add_executable(diff diff.asm) add_executable(diff diff.asm)
add_executable(3x+1 3x+1.asm) #add_executable(3x+1 3x+1.asm)

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

View file

@ -2,10 +2,11 @@
length_func: length_func:
mov r10, rdi mov r10, rdi
xor r9, r9
_loop67865432: _loop67865432:
mov r9b, [rdi] mov r9, [rdi]
cmp r9b, 0 cmp r9, 0
jz _exitloop4323567 jz _exitloop4323567
inc rdi inc rdi

View file

@ -1,17 +1,28 @@
extern puts extern puts
%include "../inc/atoi_func.inc"
section .data section .data
text db "Number reaches 1",0 text db "Number reaches 1",0
even db "even",0 even db "even",0
odd db "odd",0 odd db "odd",0
number dq 7 number db "42",0
tempstore db 0
section .text section .text
global main global main
main: main:
sub rsp, 8 sub rsp, 8
mov r8, [number] add rsi, 8
mov r8, [rsi]
mov r9, [r8]
mov [tempstore], r9
mov rdi, number
call atoi_func
mov r8, rax
_loop: _loop:
cmp r8, 1 ;if number is 1 then end cmp r8, 1 ;if number is 1 then end
je _printstupid je _printstupid

View file

@ -11,21 +11,24 @@ main:
sub rsp, 8 sub rsp, 8
mov r8, text mov rdi, text
call length_func call length_func
mov r9, rax mov r9, rax
mov r11, r9 mov r11, r9
mov r8, text mov r8, text
xor r10, r10
xor r11, r11
_loop: _loop:
mov r10b, [r8] mov r10, [r8]
cmp r10b, 0 cmp r10, 0
jz _exitloop ;if its zero we have reached the end of the string jz _exitloop ;if its zero we have reached the end of the string
mov r10b, [r8] mov r10, [r8]
sub r10b, 48 ; change "0" into 0 sub r10, 48 ; change "0" into 0
mov [r8], r10b mov [r8], r10
add r8, 1 add r8, 1
@ -40,13 +43,21 @@ _exitloop:
mov r10b [r9] mov r10, r9
mul r10b, rcx
mov [r9], r10b mov rax, r10
mul rcx
mov r10, rax
mov [r9], r10
sub r9, 1 sub r9, 1
mul rcx, 10
mov rdi, 10
mov rax, rcx
mul rdi
mov rcx, rax
jmp _exitloop jmp _exitloop
add r9, 1 add r9, 1
@ -55,10 +66,10 @@ _addvalues:
je _end je _end
mov r10b, [r8] mov r10, [r8]
mov r11b, [r9] mov r11, [r9]
add r11b, r10b add r11, r10
mov [r9], r11b mov [r9], r11