aboutsummaryrefslogtreecommitdiff
path: root/tinycc/tests/tests2/127_asm_goto.c
diff options
context:
space:
mode:
authorUneven Prankster <unevenprankster@protonmail.com>2023-07-12 13:22:29 -0300
committerUneven Prankster <unevenprankster@protonmail.com>2023-07-12 13:22:29 -0300
commitfa2bdd711212ba6b7a94a20971e8bfa281e73296 (patch)
tree6713b3c0379507d49558287b71dd360ce188a2f0 /tinycc/tests/tests2/127_asm_goto.c
lol
Diffstat (limited to 'tinycc/tests/tests2/127_asm_goto.c')
-rw-r--r--tinycc/tests/tests2/127_asm_goto.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tinycc/tests/tests2/127_asm_goto.c b/tinycc/tests/tests2/127_asm_goto.c
new file mode 100644
index 0000000..de631aa
--- /dev/null
+++ b/tinycc/tests/tests2/127_asm_goto.c
@@ -0,0 +1,62 @@
+static int simple_jump(void)
+{
+ asm goto ("jmp %l[label]" : : : : label);
+ return 0;
+label:
+ return 1;
+}
+
+static int three_way_jump(int val, int *addr)
+{
+ *addr = 42;
+ asm goto ("cmp $0, %1\n\t"
+ "jg %l[larger]\n\t"
+ "jl %l[smaller]\n\t"
+ "incl %0\n\t"
+ : "=m" (*addr)
+ : "r" (val)
+ :
+ : smaller, larger);
+ return 1;
+smaller:
+ return 2;
+larger:
+ return 3;
+}
+
+static int another_jump(void)
+{
+ asm goto ("jmp %l[label]" : : : : label);
+ return 70;
+ /* Use the same label name as in simple_jump to check that
+ that doesn't confuse our C/ASM symbol tables */
+label:
+ return 71;
+}
+
+extern int printf (const char *, ...);
+int main(void)
+{
+ int i;
+ if (simple_jump () == 1)
+ printf ("simple_jump: okay\n");
+ else
+ printf ("simple_jump: wrong\n");
+ if (another_jump () == 71)
+ printf ("another_jump: okay\n");
+ else
+ printf ("another_jump: wrong\n");
+ if (three_way_jump(0, &i) == 1 && i == 43)
+ printf ("three_way_jump(0): okay\n");
+ else
+ printf ("three_way_jump(0): wrong (i=%d)\n", i);
+ if (three_way_jump(1, &i) == 3 && i == 42)
+ printf ("three_way_jump(1): okay\n");
+ else
+ printf ("three_way_jump(1): wrong (i=%d)\n", i);
+ if (three_way_jump(-1, &i) == 2 && i == 42)
+ printf ("three_way_jump(-1): okay\n");
+ else
+ printf ("three_way_jump(-1): wrong (i=%d)\n", i);
+ return 0;
+}