2021-10-02 09:10:03 -04:00
|
|
|
extern puts
|
2021-10-04 15:15:14 -04:00
|
|
|
extern libz_atoi
|
2021-10-02 18:48:39 -04:00
|
|
|
|
2021-10-02 09:10:03 -04:00
|
|
|
section .data
|
|
|
|
text db "Number reaches 1",0
|
|
|
|
even db "even",0
|
|
|
|
odd db "odd",0
|
2021-10-04 15:15:14 -04:00
|
|
|
number dq "3761683061822795265",0
|
2021-10-02 18:48:39 -04:00
|
|
|
tempstore db 0
|
2021-10-02 09:10:03 -04:00
|
|
|
section .text
|
|
|
|
global main
|
|
|
|
|
|
|
|
main:
|
|
|
|
sub rsp, 8
|
|
|
|
|
2021-10-04 15:15:14 -04:00
|
|
|
; add rsi, 8
|
|
|
|
; mov r8, [rsi]
|
|
|
|
; mov r9, [r8]
|
|
|
|
; mov [tempstore], r9
|
2021-10-02 18:48:39 -04:00
|
|
|
|
|
|
|
mov rdi, number
|
2021-10-04 15:15:14 -04:00
|
|
|
call libz_atoi
|
2021-10-02 18:48:39 -04:00
|
|
|
mov r8, rax
|
|
|
|
|
2021-10-02 09:10:03 -04:00
|
|
|
_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
|