aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2023-06-17 15:27:50 +0200
committerMarvin Borner2023-06-17 15:27:50 +0200
commit075378188e117b13d03b39b2f43726ab0a928d62 (patch)
tree052fbc7958cc4f0d25ebcf87d3b074584c91eb93
parenta713622831076fb237c0adb3940b9bab1b75ed58 (diff)
Added config file
-rw-r--r--config.asm2
-rw-r--r--sort.asm33
2 files changed, 21 insertions, 14 deletions
diff --git a/config.asm b/config.asm
new file mode 100644
index 0000000..5ff521a
--- /dev/null
+++ b/config.asm
@@ -0,0 +1,2 @@
+%define USE_SYSCALL 0
+%define TIMEOUT 1
diff --git a/sort.asm b/sort.asm
index 50e7461..feb91cb 100644
--- a/sort.asm
+++ b/sort.asm
@@ -1,4 +1,5 @@
; Copyright (c) 2023 Marvin Borner
+%include "config.asm"
global main
extern printf
@@ -27,21 +28,11 @@ end:
mov rdi, 0
syscall ; exit
-; this works sometimes (if numbers are good)
-; uses busy loop
-coolsleep:
- mov rax, 0x4242424
- mov rcx, rsi
- mul rcx
-.loop:
- dec rax
- jnz .loop
- ret
+%if USE_SYSCALL
-; this works on most normal CPUs (if numbers are good)
; uses nanosleep syscall
-boringsleep:
- mov rax, 0x424242
+sleep:
+ mov rax, TIMEOUT ; 0x424242
mov rcx, rsi
mul rcx
push qword rax ; ns
@@ -53,9 +44,23 @@ boringsleep:
add rsp, 16
ret
+%else
+
+; uses busy loop
+sleep:
+ mov rax, TIMEOUT ; 0x4242424
+ mov rcx, rsi
+ mul rcx
+.loop:
+ dec rax
+ jnz .loop
+ ret
+
+%endif
+
print:
push rsi
- call boringsleep ; or coolsleep
+ call sleep
pop rsi
mov rdi, format
xor rax, rax