Compare commits

..

3 commits

Author SHA1 Message Date
b5946dc338 asdasasdasd hpe this works and doesnt fuck everythign up
Merge branch 'master' of ssh://play.qtechofficial.com:9940/ZNG_Zombie-Not-GNU/zombie-core-utils
2021-10-02 20:50:08 -04:00
e1c8d1f740 did some things idk 2021-10-02 18:48:39 -04:00
d0cbf26c4a added 3x+1
todo gotta make it get your number from argument, so i need to get strnum working
2021-10-02 09:10:03 -04:00
5 changed files with 198 additions and 15 deletions

View file

@ -22,7 +22,6 @@ 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(arg arg.asm)
target_link_libraries(length z) target_link_libraries(length z)
target_link_libraries(case z) target_link_libraries(case z)

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

73
monkie/3x+1.asm Normal file
View file

@ -0,0 +1,73 @@
extern puts
%include "../inc/atoi_func.inc"
section .data
text db "Number reaches 1",0
even db "even",0
odd db "odd",0
number db "42",0
tempstore db 0
section .text
global main
main:
sub rsp, 8
add rsi, 8
mov r8, [rsi]
mov r9, [r8]
mov [tempstore], r9
mov rdi, number
call atoi_func
mov r8, rax
_loop:
cmp r8, 1 ;if number is 1 then end
je _printstupid
test r8, 1 ;odd even check
jnz _odd
jz _even
_odd:
; mov rdi, odd
; cld
; call puts
mov rax, r8 ; gotta do this because mul only takes one argument
mov r9, 3
mul r9
add rax, 1
mov r8, rax
jmp _loop
_even:
; mov rdi, even
; cld
; call puts
xor rdx, rdx
mov rax, r8
mov rcx, 2
div rcx
mov r8, rax
jmp _loop
_printstupid:
mov rdi, text
cld
call puts ;this is the put s way of printing a string
_end:
add rsp, 8
ret

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,12 +43,20 @@ _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
@ -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