Hi guys, I'm currenty writing a program to simulate page replacement, and I'm given a series of virtual addresses in the form of:
0x6873
0x6cff
0x68ec
0xb148
I'm currently going to check to see if the v-address is in the TLB (translation look aside buffer) and if its not in there I'm going to check to see if its in the Page table.
But what I need to do is extract the most signifincant 4 bits and convert that to an integer and use that number as the page # to look inside the tlb/page table.
So if i was given 0xb148, I need to extract the b.
Any ideas?
Thanks
NOTE: I'm reading and storing those addresses in an unsigned integer: if ( fscanf( fp, "%d %x\n", pid, vaddr ) == 2 ); so vaddr contains the value 0xb148, and vaddr data type is: unsigned int *vaddr
Here's the full code of me reading the file and assigning the vaddress to the varaible:
Code:
int get_memory_access( FILE *fp, int *pid, unsigned int *vaddr, int *op, int *eof )
{
int err = 0;
*op = 0; /* read */
/* create processes, including initial page table */
if ( fscanf( fp, "%d %x\n", pid, vaddr ) == 2 );
else *eof = 1;
/* write: for certain addresses (< 0x200) */
if (( *vaddr - (( *vaddr / PAGE_SIZE ) * PAGE_SIZE)) < 0x200 ) {
*op = 1;
printf( "get_memory_access: process %d writes at 0x%x\n", *pid, *vaddr );
}
return err;
}
Someone told me to do the following:
vaddress >> 12
vaddress meaning that is what is storing the value: 0xb148
but i'm not sure how this is working exactly