From 823d811f53865759f12bbe2e9d55d00531ee7ee5 Mon Sep 17 00:00:00 2001 From: Isaac Shoebottom Date: Tue, 14 Nov 2023 22:16:27 -0400 Subject: [PATCH] Create project --- Lab5/.idea/.gitignore | 8 +++ Lab5/.idea/Lab5.iml | 2 + Lab5/.idea/cmake.xml | 8 +++ Lab5/.idea/editor.xml | 86 +++++++++++++++++++++++++++++ Lab5/.idea/misc.xml | 4 ++ Lab5/.idea/modules.xml | 8 +++ Lab5/.idea/vcs.xml | 6 ++ Lab5/CMakeLists.txt | 6 ++ Lab5/{ => documentation}/template.c | 0 Lab5/main.c | 36 ++++++++++++ 10 files changed, 164 insertions(+) create mode 100644 Lab5/.idea/.gitignore create mode 100644 Lab5/.idea/Lab5.iml create mode 100644 Lab5/.idea/cmake.xml create mode 100644 Lab5/.idea/editor.xml create mode 100644 Lab5/.idea/misc.xml create mode 100644 Lab5/.idea/modules.xml create mode 100644 Lab5/.idea/vcs.xml create mode 100644 Lab5/CMakeLists.txt rename Lab5/{ => documentation}/template.c (100%) create mode 100644 Lab5/main.c diff --git a/Lab5/.idea/.gitignore b/Lab5/.idea/.gitignore new file mode 100644 index 0000000..1c2fda5 --- /dev/null +++ b/Lab5/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Lab5/.idea/Lab5.iml b/Lab5/.idea/Lab5.iml new file mode 100644 index 0000000..6d70257 --- /dev/null +++ b/Lab5/.idea/Lab5.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Lab5/.idea/cmake.xml b/Lab5/.idea/cmake.xml new file mode 100644 index 0000000..c4a79cb --- /dev/null +++ b/Lab5/.idea/cmake.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab5/.idea/editor.xml b/Lab5/.idea/editor.xml new file mode 100644 index 0000000..b449c1a --- /dev/null +++ b/Lab5/.idea/editor.xml @@ -0,0 +1,86 @@ + + + + + \ No newline at end of file diff --git a/Lab5/.idea/misc.xml b/Lab5/.idea/misc.xml new file mode 100644 index 0000000..f1c67df --- /dev/null +++ b/Lab5/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Lab5/.idea/modules.xml b/Lab5/.idea/modules.xml new file mode 100644 index 0000000..b9224d5 --- /dev/null +++ b/Lab5/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lab5/.idea/vcs.xml b/Lab5/.idea/vcs.xml new file mode 100644 index 0000000..2e3f692 --- /dev/null +++ b/Lab5/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Lab5/CMakeLists.txt b/Lab5/CMakeLists.txt new file mode 100644 index 0000000..f4b6db0 --- /dev/null +++ b/Lab5/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.20) +project(Lab5 C) + +set(CMAKE_C_STANDARD 99) + +add_executable(Lab5 main.c) diff --git a/Lab5/template.c b/Lab5/documentation/template.c similarity index 100% rename from Lab5/template.c rename to Lab5/documentation/template.c diff --git a/Lab5/main.c b/Lab5/main.c new file mode 100644 index 0000000..a3eaebe --- /dev/null +++ b/Lab5/main.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