aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/array-addr-mask.c6
-rw-r--r--test/array-indirect.c13
-rw-r--r--test/array-out-of-bounds.c9
-rw-r--r--test/array-volatile.c7
-rw-r--r--test/array-write.c12
-rw-r--r--test/matrix2.c23
6 files changed, 70 insertions, 0 deletions
diff --git a/test/array-addr-mask.c b/test/array-addr-mask.c
new file mode 100644
index 0000000..5ba5601
--- /dev/null
+++ b/test/array-addr-mask.c
@@ -0,0 +1,6 @@
+int main() {
+ unsigned int x[8] = {1,2,3,4,5,6,7,8};
+ unsigned int index = 6;
+ unsigned int addr = index & 3;
+ return (x[addr]);
+}
diff --git a/test/array-indirect.c b/test/array-indirect.c
new file mode 100644
index 0000000..0315da1
--- /dev/null
+++ b/test/array-indirect.c
@@ -0,0 +1,13 @@
+int main() {
+ int index[2] = {1, 0};
+ int x[2] = {5, 10};
+ int y[2] = {0, 0};
+ for(int i=0; i<2;i++){
+ y[i] = x[index[i]] * (i+1);
+ }
+
+ int sum = 0;
+ for(int j=0; j <2; j++)
+ sum += y[j];
+ return sum;
+}
diff --git a/test/array-out-of-bounds.c b/test/array-out-of-bounds.c
new file mode 100644
index 0000000..1f20c0c
--- /dev/null
+++ b/test/array-out-of-bounds.c
@@ -0,0 +1,9 @@
+int main() {
+ int x[2] = {1, 2};
+ int y[2] = {3, 4};
+ x[2] = 0;
+ int sum = 0;
+ for(int i=0; i<2; i++)
+ sum += (x[i] * y[i]);
+ return sum;
+}
diff --git a/test/array-volatile.c b/test/array-volatile.c
new file mode 100644
index 0000000..f12b79a
--- /dev/null
+++ b/test/array-volatile.c
@@ -0,0 +1,7 @@
+int main() {
+ int x[2] = {5, 10};
+ volatile int sum;
+ for(int j=0; j <2; j++)
+ sum += x[j];
+ return sum;
+}
diff --git a/test/array-write.c b/test/array-write.c
new file mode 100644
index 0000000..697d6ed
--- /dev/null
+++ b/test/array-write.c
@@ -0,0 +1,12 @@
+int main() {
+ int x[2] = {5, 10};
+ int y[2]; //= {0 , 0};
+ for(int i=0; i<2;i++){
+ y[i] += x[i] ;
+ }
+
+ int sum = 0;
+ for(int j=0; j <2; j++)
+ sum += y[j];
+ return sum;
+}
diff --git a/test/matrix2.c b/test/matrix2.c
new file mode 100644
index 0000000..96571be
--- /dev/null
+++ b/test/matrix2.c
@@ -0,0 +1,23 @@
+void matrix_multiply(int first[][2], int second[][2], int multiply[][2], int m, int q, int p, int *totalSum) {
+ int sum = 0;
+ for (int c = 0; c < m; c++) {
+ for (int d = 0; d < q; d++) {
+ for (int k = 0; k < p; k++) {
+ sum = sum + first[c][k]*second[k][d];
+ }
+ multiply[c][d] = sum;
+ *totalSum += sum;
+ sum = 0;
+ }
+ }
+}
+
+int main() {
+ int f[2][2] = {{1, 2}, {3, 4}};
+ int s[2][2] = {{1, 2}, {3, 4}};
+ int m[2][2] = {{0, 0}, {0, 0}};
+ int sum = 0;
+
+ matrix_multiply(f, s, m, 2, 2, 2, &sum);
+ return sum;
+}