I'm trying to write a function that takes a 32bit address and a data to store at this address.
I'm watning to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78
then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF
So in this example, 0x12 points to 0x34 in the second array, which
points to 0x56 in the third array, which finally points to 0x78 in the
last array.
This last array holds the actual data.
After successfully doing 0x12345678, say I might get a read for
0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.
The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.
It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it.
I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.
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
|
void cpu::store(unsigned int mem_add,unsigned int mem_val)
{
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);
if (A1[first]==NULL)
{
int** A2=new int*[256];
for (i=0;i<256;i++)
{
A2[i]=NULL;
}
int** A3=new int*[256];
for (i=0;i<256;i++)
{
A3[i]=NULL;
}
unsigned int* A4=new unsigned int[256];
for (i=0;i<256;i++)
{
A4[i]=0;
}
A1[first]=A2;
A2[second]=A3;
A3[third]=A4;
A4[fourth]=mem_val;
}
}
|
A1 has been declared as
int* A1[256] ;
Any tips on where I'm going wrong?