summaryrefslogtreecommitdiff
path: root/3/6_control/30_switch2.c
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2024-05-28 08:49:46 +0200
committerMike Vink <mike@pionative.com>2024-05-28 08:49:46 +0200
commitb424517a33bf61aedff29eed74a665402ab496ba (patch)
tree1897e147cf15f5c7a121a73fc003b32639a697ea /3/6_control/30_switch2.c
parent758543aef80c3b3568a20b0dff20202c796a4819 (diff)
procedures
Diffstat (limited to '3/6_control/30_switch2.c')
-rw-r--r--3/6_control/30_switch2.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/3/6_control/30_switch2.c b/3/6_control/30_switch2.c
new file mode 100644
index 0000000..0c8cc85
--- /dev/null
+++ b/3/6_control/30_switch2.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+
+// x in %rdi
+// switch2:
+// addq $1, %rdi
+// cmpq $8, %rdi
+// ja .L2 if (x + 1) > 8 then goto default
+// jmp *.L4(,%rdi,8) take the address at x*8 from .L4
+void switch2(long x, long *dest) {
+ long val = 0;
+ switch (x) {
+ case -1:
+ printf(".L9");
+ break;
+ case 0:
+ case 7:
+ printf(".L5");
+ break;
+ case 1:
+ printf(".L6");
+ break;
+ case 2:
+ case 4:
+ printf(".L7");
+ break;
+ case 5:
+ printf(".L8");
+ break;
+
+ }
+ *dest = val;
+}
+
+int main(void) {
+ printf("val: %ld\n");
+ return 0;
+}