added assignment3, ex1 not working...
authorMart Lubbers <mart@martlubbers.net>
Mon, 23 Feb 2015 13:42:26 +0000 (14:42 +0100)
committerMart Lubbers <mart@martlubbers.net>
Mon, 23 Feb 2015 13:42:26 +0000 (14:42 +0100)
ass3/assignment3.pdf [new file with mode: 0644]
ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c [new file with mode: 0644]
ass3/mart/sws1-assignment3-s4109503-s4202015/exercise2.c [new file with mode: 0644]
ass3/mart/sws1-assignment3-s4109503-s4202015/exercise3 [new file with mode: 0644]
ass3/mart/sws1-assignment3-s4109503-s4202015/mf.c [new file with mode: 0644]

diff --git a/ass3/assignment3.pdf b/ass3/assignment3.pdf
new file mode 100644 (file)
index 0000000..38c7fa8
Binary files /dev/null and b/ass3/assignment3.pdf differ
diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c b/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise1.c
new file mode 100644 (file)
index 0000000..8f94702
--- /dev/null
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+
+int main(void)
+{
+       char a = 0;
+       magic_function();
+       char b = 0;
+       printf("%p\n", &a);
+       printf("%p\n", &b);
+
+       return 0;
+}
diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise2.c b/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise2.c
new file mode 100644 (file)
index 0000000..30ab2a4
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdlib.h>
+
+typedef unsigned char uc;
+typedef unsigned __int128 uint128;
+
+void addvector(int *r, const int *a, const int *b, size_t len)
+{
+       for(int *r2 = r; r2 < r + len;r2++, a++, b++)
+               *r2 = *a + *b;
+}
+
+int memcmp(const void *s1, const void *s2, size_t n)
+{
+       for(uc *s3 = (uc*)s1, *s4 = (uc*)s2; s3 < (uc*)s1 + n; s3++, s4++)
+               if(*s3 != *s4)
+                       return *s3-*s4;
+       return 0;
+}
+
+int memcmp_backwards(const void *s1, const void *s2, size_t n)
+{
+       for(uc *s3 = (uc*)s1+n, *s4 = (uc*)s2+n; s3 >= (uc*)s1; s3--, s4--)
+               if(*s3 != *s4)
+                       return *s3-*s4;
+       return 0;
+}
+
+int memcmp_fast(const void *s1, const void *s2, size_t n)
+{
+       uint128 *s3 = (uint128 *)s1;
+       uint128 *s4 = (uint128 *)s2;
+       unsigned int blocks = n/sizeof(uint128);
+       for(; s3<((uint128*)s1)+blocks; s3++, s4++)
+               if(*s3 != *s4) 
+                       return memcmp(s3, s4, sizeof(uint128));
+       return memcmp(s3, s4, n % sizeof(uint128));
+}
diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise3 b/ass3/mart/sws1-assignment3-s4109503-s4202015/exercise3
new file mode 100644 (file)
index 0000000..eaea4ef
--- /dev/null
@@ -0,0 +1,17 @@
+a) 0x7fffb3cc3b20 
+   Location of the array
+
+b) 0x7fffb3cc3b24
+   Location of first element plus sizeof(4)
+
+c) 0x7fffb3cc3b30
+   Location of array plus sizeof(4*4)
+
+d) 25
+   Value of x[0]
+
+e) 28
+   Value of x[0] plus the value of x[2]
+
+f) 151
+   Value of x[0] plus the value of x[3]
diff --git a/ass3/mart/sws1-assignment3-s4109503-s4202015/mf.c b/ass3/mart/sws1-assignment3-s4109503-s4202015/mf.c
new file mode 100644 (file)
index 0000000..a8be370
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdio.h>
+
+void magic_function()
+{
+       char a = 0;
+       a = a+1;
+}