-
Notifications
You must be signed in to change notification settings - Fork 0
/
arteris.c~
67 lines (58 loc) · 1.71 KB
/
arteris.c~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//This is solved without using any threads for basic understanding of the problem statement
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef unsigned char uint8; //Using a new variable uint8 which is an unsigned byte type for byte operations
uint8* x; //uint8 pointer pointing to an address
uint8 random_gen[64];
int ErrorCheck()
{
size_t i;
//Error checking condition after incrementing the byte address values
for(i=0;i < 64;i++)
{
//printf("Byte %d = %d\n", i, *(x+i));
if(*(x+i) != random_gen[i])
{
printf("Byte %d fails\n", i);
return -1;
}
}
return 1;
}
int main()
{
//Using time and srand for randomization
time_t t;
srand((unsigned) time(&t));
//allocating 64 bytes of memory in heap for a random address(x denotes starting of the cacheline)
x = (uint8*)malloc(64*sizeof(uint8));
if(!x)
printf("Error:Memory not allocated\n");
//counters declared for accessing memory locations
size_t i,j;
uint8* temp = x; //using a new pointer which has the same value as x for processing
for(i=0;i<64;i++)
{
*(temp+i) = (uint8)0; //Initializing all the byte addresses with 0
//printf("%u\t", *(temp+i));
random_gen[i] = rand()%255; //Finding a Random number for each byte using rand()
//printf("Random for byte %d is %d\n", i, random_gen[i]);
}
//incrementing the byte address values upto the random value generated for the respective bytes
for(i=0;i < 64 ;i++)
{
for(j=0;*(temp+i)<random_gen[i];j++)
{
// printf("%d\n",byte[i]);
temp[i]++;
}
//printf("Byte %d after random add is %d\n", i, byte[i]);
}
int Error_checker = ErrorCheck();
if(Error_checker == -1)
printf("Error in the memory\n");
else
printf("No Error all cases passed\n");
return 0;
}