ex4 done
[sws1-1415.git] / ass3 / mart / sws1-assignment3-s4109503-s4202015 / exercise1.c
1 #include <stdio.h>
2 #include <stdint.h>
3 #include "magicfunction.h"
4 #define MAX 4194304/sizeof(uint64_t)
5 uint64_t determine_start()
6 {
7 return 0x567856785678;
8 }
9 int main(void)
10 {
11 uint64_t filler = 0x123412341234;
12 uint64_t *p;
13 uint64_t *q;
14 uint64_t stack = 0;
15 /*Fill the stack with a filler value*/
16 for(p = &stack -1; p >= &stack - 1 - MAX; p--)
17 *p = filler;
18 /*Find the beginning of the function stack with the function*/
19 determine_start();
20 for(q = &stack -1; q>=&stack-1-MAX; q--)
21 if(*q == 0x567856785678)
22 break;
23 /*Run the function and find the last occurance of non stack filler */
24 magic_function();
25 for(p = &stack - 1 - MAX; p <= q; p++)
26 if(*p != filler)
27 break;
28 printf("%td byte stack size used\n", (char*)p-(char*)q);
29 return 0;
30 }