aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2023-06-15 21:09:04 +0200
committerMarvin Borner2023-06-15 21:09:04 +0200
commit746a227e08e35abbf556be228f37cfbcfc60ee41 (patch)
tree4589ed0eab14d3b35012f6395f1cfa51d340d901
parentf7638fc25078314e1b64134436af7bcbf9a9c2ee (diff)
Added threading
-rw-r--r--sort.asm56
1 files changed, 45 insertions, 11 deletions
diff --git a/sort.asm b/sort.asm
index b576889..d089dc9 100644
--- a/sort.asm
+++ b/sort.asm
@@ -1,29 +1,63 @@
; Copyright (c) 2023 Marvin Borner
-global main
-extern printf
+global main
+extern printf
-bits 64
+bits 64
+
+;;; main
main:
push rbp
mov ecx, size
-print:
- mov rdi, format
- mov rsi, [array + (ecx - 1) * 4]
- xor rax, rax
+loop:
push rcx
- call printf WRT ..plt
+ call thread
pop rcx
dec ecx
- jnz print
+ jnz loop
end:
pop rbp
- mov rax, 0
+ mov rax, 0x3c
+ mov rdi, 0
+ syscall ; exit
+
+print:
+ mov rdi, format
+ xor rax, rax
+ call printf
ret
-array: dd 1, 5, 3, 7, 2, 6
+thread:
+ lea rax, print
+ mov rsi, [array + (ecx - 1) * 4]
+ call thread_run
+ ret
+
+;;; utils
+
+thread_run:
+ push rax
+ mov rax, 0x39
+ syscall ; fork
+ cmp rax, 0
+ mov r10, rax
+ pop rax
+ je child
+ mov rax, r10
+ ret
+
+child:
+ call rax
+
+ mov rax, 0x3c
+ mov rdi, 0
+ syscall ; exit
+
+;;; data
+
+array: dd 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3
size: equ ($-array)/4
format: db "%d", 10, 0