Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finsihed memory

  • Loading branch information...
commit 4a328094f3198befbc10633c62f13fe8b2f0c5f3 1 parent eb0f669
@pksunkara authored
Showing with 36 additions and 22 deletions.
  1. +10 −5 access.cpp
  2. +4 −2 access.h
  3. +4 −4 main.cpp
  4. +12 −7 memory.cpp
  5. +6 −4 memory.h
View
15 access.cpp
@@ -4,16 +4,21 @@
using namespace std;
-Access::Access(int matrix_n) {
- this->memory = new Memory(matrix_n);
+Access::Access(int matrix_n, int memory_size) {
+ this->matrix_n = matrix_n;
+ this->memory = new Memory(memory_size);
}
-void Access::write(int x, int y, int value) {
- this->memory->set(x, y, value);
+void Access::write(int value) {
+ this->memory->write(value);
+}
+
+void Access::set(int x, int y, int value) {
+ this->memory->store(x*matrix_n+y, value);
}
int Access::get(int x, int y) {
- return this->memory->get(x, y);
+ return this->memory->read(x*matrix_n+y);
}
Access::~Access(void) {
View
6 access.h
@@ -6,14 +6,16 @@
class Access {
public:
- Access(int matrix_n);
+ Access(int matrix_n, int memory_size);
- void write(int x, int y, int value);
+ void write(int value);
+ void set(int x, int y, int value);
int get(int x, int y);
~Access(void);
private:
+ int matrix_n;
Memory* memory;
};
View
8 main.cpp
@@ -16,7 +16,7 @@ int M(int, int);
int main(int argc, char** argv) {
if(argc!=5) {
- printf("Usage: %s <cache_size_inKB> <block_size_inB> <associativity> <input_file>\n", argv[0]);
+ printf("Usage: %s <cache_size_inKB> <block_size_inB> <associativity> <memory_size_inKB>\n", argv[0]);
return 1;
}
@@ -26,7 +26,7 @@ int main(int argc, char** argv) {
ifstream inFile;
// Opening files
- inFile.open(argv[4]);
+ inFile.open("INPUT");
// Checking for situation of files
if(!inFile.is_open()) {
@@ -38,13 +38,13 @@ int main(int argc, char** argv) {
inFile >> matrix_n;
// Initalize accessor
- accessor = new Access(matrix_n);
+ accessor = new Access(matrix_n, atoi(argv[4]));
// Reading matrix
for(i=0; i<matrix_n; i++) {
for(j=0; j<matrix_n; j++) {
inFile >> buf;
- accessor->write(i, j, buf);
+ accessor->write(buf);
}
}
View
19 memory.cpp
@@ -4,17 +4,22 @@
using namespace std;
-Memory::Memory(int n) {
- this->n = n;
- this->memory = new int[n*n];
+Memory::Memory(int size) {
+ this->size = size*256;
+ this->writer = 0;
+ this->memory = new int[this->size];
}
-void Memory::set(int x, int y, int value) {
- this->memory[x*n+y] = value;
+void Memory::write(int value) {
+ this->memory[writer++] = value;
}
-int Memory::get(int x, int y) {
- return this->memory[x*n+y];
+int Memory::read(int address) {
+ return this->memory[address];
+}
+
+void Memory::store(int address, int value) {
+ this->memory[address] = value;
}
Memory::~Memory(void) {
View
10 memory.h
@@ -3,16 +3,18 @@
class Memory {
public:
- Memory(int n);
+ Memory(int size);
- void set(int x, int y, int value);
- int get(int x, int y);
+ void write(int value);
+ int read(int address);
+ void store(int address, int value);
~Memory(void);
private:
int* memory;
- int n;
+ int size;
+ int writer;
};
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.