70 lines
799 B
NASM
70 lines
799 B
NASM
|
extern puts
|
||
|
|
||
|
section .data
|
||
|
text db "Number reaches 1",0
|
||
|
even db "even",0
|
||
|
odd db "odd",0
|
||
|
number db 7
|
||
|
section .text
|
||
|
global main
|
||
|
|
||
|
main:
|
||
|
sub rsp, 8
|
||
|
|
||
|
_loop:
|
||
|
mov r8d, [number]
|
||
|
|
||
|
cmp r8d, 1 ;if number is 1 then end
|
||
|
je _printstupid
|
||
|
|
||
|
test r8d, 1 ;odd even check
|
||
|
jnz _odd
|
||
|
jz _even
|
||
|
|
||
|
|
||
|
_odd:
|
||
|
mov rdi, odd
|
||
|
cld
|
||
|
call puts
|
||
|
|
||
|
mov eax, r8d ; gotta do this because mul only takes one argument
|
||
|
mov r9d, 3
|
||
|
mul r9d
|
||
|
add eax, 1
|
||
|
mov r8d, eax
|
||
|
|
||
|
jmp _loop
|
||
|
|
||
|
|
||
|
_even:
|
||
|
mov rdi, even
|
||
|
cld
|
||
|
call puts
|
||
|
|
||
|
xor edx, edx
|
||
|
mov eax, r8d
|
||
|
mov ecx, 2
|
||
|
div ecx
|
||
|
mov r8d, eax
|
||
|
|
||
|
jmp _loop
|
||
|
|
||
|
|
||
|
|
||
|
_printstupid:
|
||
|
|
||
|
mov rdi, text
|
||
|
cld
|
||
|
call puts ;this is the put s way of printing a string
|
||
|
|
||
|
|
||
|
_end:
|
||
|
add rsp, 8
|
||
|
ret
|
||
|
|
||
|
; mov eax, 60 ; exit
|
||
|
; mov edi, 1 ; error 1 dont need the exit anymore beacue libc or somthing
|
||
|
; syscall
|
||
|
|
||
|
|