summaryrefslogtreecommitdiff
path: root/tests/features/test_asm.zc
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
commitdcfdc053cb5f9fb4d5eac0a2233c75126b7a8188 (patch)
treef34f30b382fa22d6fd0af46875a5b4b26d00feff /tests/features/test_asm.zc
parenta918df69269a39ef7350a645b5db025d66ecb18a (diff)
Added some of the tests.
Diffstat (limited to 'tests/features/test_asm.zc')
-rw-r--r--tests/features/test_asm.zc54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/features/test_asm.zc b/tests/features/test_asm.zc
new file mode 100644
index 0000000..01f35d5
--- /dev/null
+++ b/tests/features/test_asm.zc
@@ -0,0 +1,54 @@
+fn test_nop() {
+ asm { nop }
+}
+
+fn test_pause() {
+ asm { pause }
+}
+
+fn test_multiline() {
+ asm {
+ mov $1, %rax
+ mov $2, %rbx
+ add %rbx, %rax
+ }
+}
+
+fn test_volatile() {
+ asm volatile {
+ mfence
+ }
+}
+
+test "test_asm" {
+ println "Testing inline assembly...";
+
+ test_nop();
+ test_pause();
+ test_multiline();
+ test_volatile();
+
+ println "-> Assembly blocks compiled successfully!";
+}
+
+fn add_five(x: int) -> int {
+ var result: int;
+ asm {
+ "mov {x}, {result}"
+ "add $5, {result}"
+ : out(result)
+ : in(x)
+ }
+ return result;
+}
+
+test "test_asm_params" {
+ println "Testing assembly parameters...";
+ var val = add_five(10);
+ if (val == 15) {
+ println "-> Success! add_five(10) = 15";
+ } else {
+ println "-> Failed: expected 15, got {val}";
+ exit(1);
+ }
+}