Skip to content

Commit 51617f3

Browse files
committed
some more examples
1 parent 172bdd8 commit 51617f3

19 files changed

+548
-0
lines changed

and-another-condition.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int lt(int x, int y) {
4+
int z = x - y;
5+
if(z) {
6+
printf("condition met");
7+
return 1;
8+
}
9+
}
10+
11+
int main() {
12+
int a = 42;
13+
int b = 73;
14+
lt(a,b);
15+
return 0;
16+
}

another-condition.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int lt(int x, int y) {
4+
int z = x + y;
5+
if(z) {
6+
printf("condition met");
7+
return 1;
8+
}
9+
}
10+
11+
int main() {
12+
int a = 42;
13+
int b = 73;
14+
lt(a,b);
15+
return 0;
16+
}

conditions.s

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.build_version macos, 10, 15 sdk_version 10, 15
3+
.globl _gt ## -- Begin function gt
4+
.p2align 4, 0x90
5+
_gt: ## @gt
6+
.cfi_startproc
7+
## %bb.0:
8+
pushq %rbp
9+
.cfi_def_cfa_offset 16
10+
.cfi_offset %rbp, -16
11+
movq %rsp, %rbp
12+
.cfi_def_cfa_register %rbp
13+
movl %edi, -4(%rbp)
14+
movl %esi, -8(%rbp)
15+
movl -4(%rbp), %esi
16+
cmpl -8(%rbp), %esi
17+
setg %al
18+
andb $1, %al
19+
movzbl %al, %eax
20+
popq %rbp
21+
retq
22+
.cfi_endproc
23+
## -- End function
24+
.globl _gte ## -- Begin function gte
25+
.p2align 4, 0x90
26+
_gte: ## @gte
27+
.cfi_startproc
28+
## %bb.0:
29+
pushq %rbp
30+
.cfi_def_cfa_offset 16
31+
.cfi_offset %rbp, -16
32+
movq %rsp, %rbp
33+
.cfi_def_cfa_register %rbp
34+
movl %edi, -4(%rbp)
35+
movl %esi, -8(%rbp)
36+
movl -4(%rbp), %esi
37+
cmpl -8(%rbp), %esi
38+
setge %al
39+
andb $1, %al
40+
movzbl %al, %eax
41+
popq %rbp
42+
retq
43+
.cfi_endproc
44+
## -- End function
45+
.globl _lt ## -- Begin function lt
46+
.p2align 4, 0x90
47+
_lt: ## @lt
48+
.cfi_startproc
49+
## %bb.0:
50+
pushq %rbp
51+
.cfi_def_cfa_offset 16
52+
.cfi_offset %rbp, -16
53+
movq %rsp, %rbp
54+
.cfi_def_cfa_register %rbp
55+
movl %edi, -4(%rbp)
56+
movl %esi, -8(%rbp)
57+
movl -4(%rbp), %esi
58+
cmpl -8(%rbp), %esi
59+
setl %al
60+
andb $1, %al
61+
movzbl %al, %eax
62+
popq %rbp
63+
retq
64+
.cfi_endproc
65+
## -- End function
66+
.globl _lte ## -- Begin function lte
67+
.p2align 4, 0x90
68+
_lte: ## @lte
69+
.cfi_startproc
70+
## %bb.0:
71+
pushq %rbp
72+
.cfi_def_cfa_offset 16
73+
.cfi_offset %rbp, -16
74+
movq %rsp, %rbp
75+
.cfi_def_cfa_register %rbp
76+
movl %edi, -4(%rbp)
77+
movl %esi, -8(%rbp)
78+
movl -4(%rbp), %esi
79+
cmpl -8(%rbp), %esi
80+
setle %al
81+
andb $1, %al
82+
movzbl %al, %eax
83+
popq %rbp
84+
retq
85+
.cfi_endproc
86+
## -- End function
87+
.globl _eq ## -- Begin function eq
88+
.p2align 4, 0x90
89+
_eq: ## @eq
90+
.cfi_startproc
91+
## %bb.0:
92+
pushq %rbp
93+
.cfi_def_cfa_offset 16
94+
.cfi_offset %rbp, -16
95+
movq %rsp, %rbp
96+
.cfi_def_cfa_register %rbp
97+
movl %edi, -4(%rbp)
98+
movl %esi, -8(%rbp)
99+
movl -4(%rbp), %esi
100+
cmpl -8(%rbp), %esi
101+
sete %al
102+
andb $1, %al
103+
movzbl %al, %eax
104+
popq %rbp
105+
retq
106+
.cfi_endproc
107+
## -- End function
108+
.globl _main ## -- Begin function main
109+
.p2align 4, 0x90
110+
_main: ## @main
111+
.cfi_startproc
112+
## %bb.0:
113+
pushq %rbp
114+
.cfi_def_cfa_offset 16
115+
.cfi_offset %rbp, -16
116+
movq %rsp, %rbp
117+
.cfi_def_cfa_register %rbp
118+
subq $32, %rsp
119+
movl $0, -4(%rbp)
120+
movl $42, -8(%rbp)
121+
movl $73, -12(%rbp)
122+
movl -8(%rbp), %edi
123+
movl -12(%rbp), %esi
124+
callq _gt
125+
movl -8(%rbp), %edi
126+
movl -12(%rbp), %esi
127+
movl %eax, -16(%rbp) ## 4-byte Spill
128+
callq _lt
129+
movl -8(%rbp), %edi
130+
movl -12(%rbp), %esi
131+
movl %eax, -20(%rbp) ## 4-byte Spill
132+
callq _gte
133+
movl -8(%rbp), %edi
134+
movl -12(%rbp), %esi
135+
movl %eax, -24(%rbp) ## 4-byte Spill
136+
callq _lte
137+
movl -8(%rbp), %edi
138+
movl -12(%rbp), %esi
139+
movl %eax, -28(%rbp) ## 4-byte Spill
140+
callq _eq
141+
xorl %esi, %esi
142+
movl %eax, -32(%rbp) ## 4-byte Spill
143+
movl %esi, %eax
144+
addq $32, %rsp
145+
popq %rbp
146+
retq
147+
.cfi_endproc
148+
## -- End function
149+
150+
.subsections_via_symbols

eq-condition.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
3+
int lt(int x, int y) {
4+
if(x == y) {
5+
printf("x ?? y");
6+
return 1;
7+
} else {
8+
printf("x ?? y");
9+
return 0;
10+
}
11+
}
12+
13+
int main() {
14+
int a = 42;
15+
int b = 73;
16+
lt(a,b);
17+
return 0;
18+
}

even-another-condition.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
3+
int lt(long x, long y) {
4+
long z = x - y;
5+
if(z) {
6+
printf("condition met");
7+
return 1;
8+
}
9+
}
10+
11+
int main() {
12+
long a = 42;
13+
long b = 73;
14+
lt(a,b);
15+
return 0;
16+
}

glocal.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <stdio.h>
2+
3+
int x = 42;
4+
5+
int f() { return x; }
6+
int g() { int x = 1; return f(); }
7+
int main() {
8+
int x = g();
9+
printf("value is %d", x);
10+
}

interproc2.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int f(int x) {
2+
return x+1;
3+
}
4+
int main() {
5+
int x = f(72);
6+
return 0;
7+
}

interproc3.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int f(int x,int y) {
2+
return x+y;
3+
}
4+
int main() {
5+
int x = f(42,31);
6+
return 0;
7+
}

interproc5.c

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
int main() {
3+
int x = 42;
4+
int y = 73;
5+
int z = 31;
6+
int w = 18;
7+
return 0;
8+
}

loop-do-while.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
3+
int func(int count) {
4+
int i =0;
5+
do {
6+
printf(i);
7+
i++;
8+
} while (i<count);
9+
}
10+
11+
int main() {
12+
long a = 42;
13+
func(a);
14+
return 0;
15+
}

loop-for.c

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
int func(int count) {
4+
int i =0;
5+
for(int i=0;i<count;i++) {
6+
printf(i);
7+
}
8+
}
9+
10+
int main() {
11+
long a = 42;
12+
func(a);
13+
return 0;
14+
}

loop-while.c

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stdio.h>
2+
3+
int func(int count) {
4+
int i =0;
5+
while(i<count) {
6+
printf(i);
7+
i++;
8+
}
9+
}
10+
11+
int main() {
12+
long a = 42;
13+
func(a);
14+
return 0;
15+
}

lt-condition.s

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.section __TEXT,__text,regular,pure_instructions
2+
.build_version macos, 10, 15 sdk_version 10, 15
3+
.globl _lt ## -- Begin function lt
4+
.p2align 4, 0x90
5+
_lt: ## @lt
6+
.cfi_startproc
7+
## %bb.0:
8+
pushq %rbp
9+
.cfi_def_cfa_offset 16
10+
.cfi_offset %rbp, -16
11+
movq %rsp, %rbp
12+
.cfi_def_cfa_register %rbp
13+
subq $32, %rsp
14+
movl %edi, -8(%rbp)
15+
movl %esi, -12(%rbp)
16+
movl -8(%rbp), %esi
17+
cmpl -12(%rbp), %esi
18+
jge LBB0_2
19+
## %bb.1:
20+
leaq L_.str(%rip), %rdi
21+
movb $0, %al
22+
callq _printf
23+
movl $1, -4(%rbp)
24+
movl %eax, -16(%rbp) ## 4-byte Spill
25+
jmp LBB0_3
26+
LBB0_2:
27+
leaq L_.str.1(%rip), %rdi
28+
movb $0, %al
29+
callq _printf
30+
movl $0, -4(%rbp)
31+
movl %eax, -20(%rbp) ## 4-byte Spill
32+
LBB0_3:
33+
movl -4(%rbp), %eax
34+
addq $32, %rsp
35+
popq %rbp
36+
retq
37+
.cfi_endproc
38+
## -- End function
39+
.globl _main ## -- Begin function main
40+
.p2align 4, 0x90
41+
_main: ## @main
42+
.cfi_startproc
43+
## %bb.0:
44+
pushq %rbp
45+
.cfi_def_cfa_offset 16
46+
.cfi_offset %rbp, -16
47+
movq %rsp, %rbp
48+
.cfi_def_cfa_register %rbp
49+
subq $16, %rsp
50+
movl $0, -4(%rbp)
51+
movl $42, -8(%rbp)
52+
movl $73, -12(%rbp)
53+
movl -8(%rbp), %edi
54+
movl -12(%rbp), %esi
55+
callq _lt
56+
xorl %esi, %esi
57+
movl %eax, -16(%rbp) ## 4-byte Spill
58+
movl %esi, %eax
59+
addq $16, %rsp
60+
popq %rbp
61+
retq
62+
.cfi_endproc
63+
## -- End function
64+
.section __TEXT,__cstring,cstring_literals
65+
L_.str: ## @.str
66+
.asciz "x is LT Y"
67+
68+
L_.str.1: ## @.str.1
69+
.asciz "x is GTE Y"
70+
71+
72+
.subsections_via_symbols

0 commit comments

Comments
 (0)