diff --git a/Lab5/Lab4-1.pdf b/Lab5/Lab4-1.pdf new file mode 100644 index 0000000..c0e53bb Binary files /dev/null and b/Lab5/Lab4-1.pdf differ diff --git a/Lab5/input.txt b/Lab5/input.txt new file mode 100644 index 0000000..e184a56 --- /dev/null +++ b/Lab5/input.txt @@ -0,0 +1,13 @@ +4097 +100 +500 +12000 +300 +8500 +5000 +25300 +4700 +13000 +15000 +22140 +27000 \ No newline at end of file diff --git a/Lab5/template.c b/Lab5/template.c new file mode 100644 index 0000000..7c3e351 --- /dev/null +++ b/Lab5/template.c @@ -0,0 +1,36 @@ +#include +#include +#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); + } +} \ No newline at end of file