summaryrefslogtreecommitdiff
path: root/stdlib/main.asm
diff options
context:
space:
mode:
authorA404M <ahmadmahmoudiprogrammer@gmail.com>2025-01-29 03:06:16 +0330
committerA404M <ahmadmahmoudiprogrammer@gmail.com>2025-01-29 03:06:16 +0330
commitf090d484ab9425be9d7e4e3f42ba4224dde35c2d (patch)
treec8f865b34257bc1bfe2f79c8147b9779a34ea3ba /stdlib/main.asm
parente20ddf634b79d6d955bf341447ea16bf944c44a9 (diff)
move assembly to new file
make constants to have a separate token
Diffstat (limited to 'stdlib/main.asm')
-rw-r--r--stdlib/main.asm39
1 files changed, 39 insertions, 0 deletions
diff --git a/stdlib/main.asm b/stdlib/main.asm
new file mode 100644
index 0000000..bd3d417
--- /dev/null
+++ b/stdlib/main.asm
@@ -0,0 +1,39 @@
+format ELF64 executable 3
+
+SYS_exit = 60
+SYS_write = 1
+STDOUT = 1
+
+segment readable executable
+entry _start
+
+; rdi = the number
+print_u64:
+mov rcx, rsp
+mov rax, rdi
+mov rbx, 10
+
+.L:
+xor rdx, rdx
+div rbx
+add dl, '0'
+dec rcx
+mov [rcx],dl
+cmp rax, 0
+jnz .L
+
+mov rax, SYS_write
+mov rdi, STDOUT
+mov rsi, rcx
+
+mov rdx, rsp
+sub rdx, rcx
+
+syscall
+ret
+
+_start:
+call main
+mov rax, SYS_exit
+xor rdi,rdi
+syscall