aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2023-06-17 15:18:10 +0200
committerMarvin Borner2023-06-17 15:18:10 +0200
commita713622831076fb237c0adb3940b9bab1b75ed58 (patch)
treef4110df4f25b8d4cd842557ccc9bec175bb07837
parent94305d2680e55dbfc363ca613146dfc2818f0171 (diff)
Added c benchmark
-rw-r--r--.gitignore3
-rw-r--r--benchmark/sort.c20
-rw-r--r--data.asm7
-rw-r--r--makefile15
-rw-r--r--sort.asm4
5 files changed, 42 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index a7f05ec..f17708e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
sort
sort.o
+data.o
+csort.o
+csort
diff --git a/benchmark/sort.c b/benchmark/sort.c
new file mode 100644
index 0000000..657d2be
--- /dev/null
+++ b/benchmark/sort.c
@@ -0,0 +1,20 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+extern int array[];
+extern int size;
+
+int compare(const void *a, const void *b)
+{
+ return *(int *)a - *(int *)b;
+}
+
+int main(int argc, char *argv[])
+{
+ int len = (int)&size; // ??
+ qsort(array, len, sizeof(int), compare);
+ for (int i = 0; i < len; i++)
+ printf("%d\n", array[i]);
+ return 0;
+}
diff --git a/data.asm b/data.asm
new file mode 100644
index 0000000..35af1c4
--- /dev/null
+++ b/data.asm
@@ -0,0 +1,7 @@
+section .data
+
+global array
+global size
+
+array: dd 3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3
+size: equ ($-array)/4
diff --git a/makefile b/makefile
index e7e2ee3..a2bec28 100644
--- a/makefile
+++ b/makefile
@@ -1,6 +1,11 @@
-SRC = sort.asm
-OBJ = sort.o
+all: asm
-all:
- @nasm -f elf64 -o $(OBJ) $(SRC)
- @gcc -no-pie -o sort $(OBJ)
+asm:
+ @nasm -f elf64 -o sort.o sort.asm
+ @nasm -f elf64 -o data.o data.asm
+ @gcc -no-pie -o sort data.o sort.o
+
+c:
+ @nasm -f elf64 -o data.o data.asm
+ @gcc -no-pie -c -o csort.o benchmark/sort.c
+ @gcc -no-pie -o csort data.o csort.o
diff --git a/sort.asm b/sort.asm
index c66b6a9..50e7461 100644
--- a/sort.asm
+++ b/sort.asm
@@ -2,6 +2,8 @@
global main
extern printf
+extern array
+extern size
bits 64
@@ -103,6 +105,4 @@ child:
section .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