From d0cbf26c4ad98a57ee207f972f97568ee86ee4ed Mon Sep 17 00:00:00 2001 From: zombie Date: Sat, 2 Oct 2021 09:10:03 -0400 Subject: [PATCH] added 3x+1 todo gotta make it get your number from argument, so i need to get strnum working --- 3x+1.asm | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 3x+1.asm diff --git a/3x+1.asm b/3x+1.asm new file mode 100644 index 0000000..b511afa --- /dev/null +++ b/3x+1.asm @@ -0,0 +1,62 @@ +extern puts + +section .data + text db "Number reaches 1",0 + even db "even",0 + odd db "odd",0 + number dq 7 +section .text + global main + +main: + sub rsp, 8 + + mov r8, [number] +_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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0eb9155..3a482b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,4 +21,4 @@ add_executable(length length.asm) add_executable(yes yes.asm) add_executable(case case.asm) add_executable(diff diff.asm) -add_executable(arg arg.asm) +add_executable(3x+1 3x+1.asm)