Website Summary Files Commits Branches @commit @diff @stats
path: root / demo
diff options
context:
space:
mode:
Commitc55d903aa7b6cdc49f172c6436b249136bddd82d (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-12-12 20:46:55 +0200
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-12-12 20:46:55 +0200
Files78bfa2366f5a1354bc32c3032d5d1aac9e4797de /demo
IPL-c55d903aa7b6cdc49f172c6436b249136bddd82d.tar
IPL-c55d903aa7b6cdc49f172c6436b249136bddd82d.tar.gz
IPL-c55d903aa7b6cdc49f172c6436b249136bddd82d.zip
Parent715632578a616f7a983553c7c6670c785bd41f2c (diff)
Add template jit slides and demo
2 files changed, 51 insertions, 0 deletions
-rw-r--r--demo/asm/add_answer.asm42
-rw-r--r--demo/asm/main.cpp9
diff --git a/demo/asm/add_answer.asm b/demo/asm/add_answer.asm
new file mode 100644
index 0000000..2864c3c
--- /dev/null
+++ b/demo/asm/add_answer.asm
@@ -0,0 +1,42 @@
+global add_answer
+
+section .text
+add_answer_2:
+ push rbp
+ mov rbp, rsp
+ mov rax, 42
+ add rax, rcx
+ pop rbp
+ ret
+
+add_answer:
+ push rbp
+ mov rbp, rsp
+ push r15
+ mov r15, rsp
+ push r9
+ push r8
+ push rcx
+ push rdx
+ push rsi
+; Handle Win64 calling convention
+; push rdi ; used by System V
+ push rcx ; used by Win64
+ push 1
+ mov rdi, rsp
+
+ mov [rdi - 8], byte 42
+
+ mov r8, [rdi + 8]
+ mov r9, [rdi - 8]
+
+ mov rcx, r8
+ add rcx, r9
+
+ mov [rdi + 16], rcx
+
+ mov eax, [rdi + 16]
+ mov rsp, r15
+ pop r15
+ pop rbp
+ ret
diff --git a/demo/asm/main.cpp b/demo/asm/main.cpp
new file mode 100644
index 0000000..ec9ba10
--- /dev/null
+++ b/demo/asm/main.cpp
@@ -0,0 +1,9 @@
+#include <cstdio>
+#include <cstdint>
+
+extern "C" int64_t add_answer(int64_t x);
+
+int main() {
+ std::printf("The result is %lld\n", add_answer(24));
+ return 0;
+}