zombie-core-utils/3x+1.asm

72 lines
820 B
NASM

extern puts
extern libz_atoi
section .data
text db "Number reaches 1",0
even db "even",0
odd db "odd",0
number dq "496489",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 libz_atoi
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