CS3413/Lab5/documentation/template.c
2023-11-14 22:16:27 -04:00

36 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#define OFFSETBITS 12
// fancy way of computing 2^OFFSETBITS
#define PAGESIZE (1 << OFFSETBITS)
#define WORDSIZE 32
int getPageNumber(int logicalAddress){
return logicalAddress / PAGESIZE ;
}
int getPageOffset(int logicalAddress){
return logicalAddress % PAGESIZE ;
}
int getStartingAddressOfTheFrameByIndex(int indexInFramesArray){
return indexInFramesArray*PAGESIZE ;
}
int main(int argc, char** argv){
/* int* frames = malloc the recommended array here*/;
int maxPreviouslyUsedFrame = 0;
int logicalAddress;
int i;
int hasAFrameAssignedBefore = 0;
int tempFrameIndex=0;
while(EOF != scanf("%d\n",&logicalAddress) )
{
/** reset the value of hasAFrameAssignedBefore to 0 */
/* for all the values from 0 to maxPreviouslyUsedFrame, check if there's a page number of the current logical address in the frame array. if it is, mark hasAFrameAssignedBefore as 1 and store the index of the frame you just found into tempFrameIndex */
/* After looking up through all the values from 0 to maxPreviouslyUsedFrame, if the page did not have a frame assigned before, assign the page number to the frame array
in the maxPreviously used frame position, store the max previously used frame into tempFrameIndex, increment the value of the maxPreviously used frame */
/* now that you have the physical frame index corresponding to your page stored in tempFrameIndex, get the starting address of the frame by index and add the page offset to it and voila, you have your physical address. Print it out in the format
printf("Physical address is %i logical address is %i\n" ..);
*/
printf("Read %i\n",logicalAddress);
}
}