diff --git a/.gitignore b/.gitignore index ea24011..9393c5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ printf/build/ +3x+1/build/ +float/build/ diff --git a/3x+1/CMakeLists.txt b/3x+1/CMakeLists.txt new file mode 100644 index 0000000..bca0339 --- /dev/null +++ b/3x+1/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.14) +project (hello) + +#set(CMAKE_ASM_NASM_LINK_EXECUTABLE ld) + + +#Set C++ language version +set(CMAKE_CXX_STANDARD 17) +#Enable ASM provided by NASM +enable_language(ASM_NASM) + +set(CMAKE_ASM_NASM_LINK_EXECUTABLE "gcc -o ") + +add_link_options(-fno-pie -m64 -no-pie -pedantic-errors) + +#Make a EXE with cpp and asm files +add_executable(hello hello.asm) diff --git a/3x+1/hello.asm b/3x+1/hello.asm new file mode 100644 index 0000000..bf58b92 --- /dev/null +++ b/3x+1/hello.asm @@ -0,0 +1,69 @@ +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 + + diff --git a/float/CMakeLists.txt b/float/CMakeLists.txt new file mode 100644 index 0000000..bca0339 --- /dev/null +++ b/float/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.14) +project (hello) + +#set(CMAKE_ASM_NASM_LINK_EXECUTABLE ld) + + +#Set C++ language version +set(CMAKE_CXX_STANDARD 17) +#Enable ASM provided by NASM +enable_language(ASM_NASM) + +set(CMAKE_ASM_NASM_LINK_EXECUTABLE "gcc -o ") + +add_link_options(-fno-pie -m64 -no-pie -pedantic-errors) + +#Make a EXE with cpp and asm files +add_executable(hello hello.asm) diff --git a/float/hello.asm b/float/hello.asm new file mode 100644 index 0000000..17a7344 --- /dev/null +++ b/float/hello.asm @@ -0,0 +1,56 @@ +default rel ; make [rel format] the default, you always want this. idk why i always want this but im taking it anyway +extern puts +extern printf + + + +section .data + text db "Bottom Text",0 + val dq 123.45 + +section .bss + res resq 1 ; reserve 1 quadword for result + +section .rodata + format db "%#f", 10, 0 ; C 0-terminated string: "%#x\n" idk why this is in its own section im just stealing code + +section .text + global main + +main: + sub rsp, 8 ;this is needed because im using "C" + + + ; load value into st(0) + fld qword [val] ; treat val as an address to a qword + + ; compute square root of st(0) and store the result in st(0) + fsqrt ; + + ; store st(0) at res, and pop it off the x87 stack + fstp qword [res] + + ; the FPU stack is now empty again + + + + + mov rdi, res + cld + call puts ;this is the puts way of printing a string + + mov esi, res + lea rdi, [rel format] + cld + call printf + + +_end: + add rsp, 8 + ret + +; mov rax, 60 ; exit +; mov edi, 1 ; error 1 dont need the exit anymore beacue libc or somthing +; syscall + +