added 3x+1
todo gotta make it get your number from argument, so i need to get strnum working
This commit is contained in:
parent
415651cd0e
commit
d0cbf26c4a
2 changed files with 63 additions and 1 deletions
62
3x+1.asm
Normal file
62
3x+1.asm
Normal file
|
@ -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
|
|
@ -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(arg arg.asm)
|
add_executable(3x+1 3x+1.asm)
|
||||||
|
|
Loading…
Reference in a new issue