asdasdasdasdasdasdasdasd*&^%$#$%^&*(O
This commit is contained in:
parent
522781456c
commit
c39662c988
5 changed files with 161 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
|||
printf/build/
|
||||
3x+1/build/
|
||||
float/build/
|
||||
|
|
17
3x+1/CMakeLists.txt
Normal file
17
3x+1/CMakeLists.txt
Normal file
|
@ -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 <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||
|
||||
add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
|
||||
|
||||
#Make a EXE with cpp and asm files
|
||||
add_executable(hello hello.asm)
|
69
3x+1/hello.asm
Normal file
69
3x+1/hello.asm
Normal file
|
@ -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
|
||||
|
||||
|
17
float/CMakeLists.txt
Normal file
17
float/CMakeLists.txt
Normal file
|
@ -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 <CMAKE_ASM_NASM_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
|
||||
|
||||
add_link_options(-fno-pie -m64 -no-pie -pedantic-errors)
|
||||
|
||||
#Make a EXE with cpp and asm files
|
||||
add_executable(hello hello.asm)
|
56
float/hello.asm
Normal file
56
float/hello.asm
Normal file
|
@ -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 <it has to know that its a qword i think idk this shit is scary>
|
||||
|
||||
; compute square root of st(0) and store the result in st(0)
|
||||
fsqrt ;<so like the fpu has like its own registers that cant be used with mov and they act as a stack or somthing and its fucking scary help me>
|
||||
|
||||
; 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
|
||||
|
||||
|
Loading…
Reference in a new issue