-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmemAccess.c
43 lines (35 loc) · 973 Bytes
/
memAccess.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdlib.h>
#include "memAccess.h"
#include "execute.h"
MemAccess *MemAccessInit(int *mem, ExecuteMemAccess *inBucket,
MemAccessWriteback *outBucket) {
MemAccess *memacc = malloc(sizeof(MemAccess));
memacc->count = 0;
memacc->inBucket = inBucket;
memacc->outBucket = outBucket;
memacc->mem = mem;
return memacc;
}
void MemAccessPhase(MemAccess *memAccess) {
ExecuteMemAccess *in = memAccess->inBucket;
MemAccessWriteback *out = memAccess->outBucket;
if (!in->ready)
return;
in->ready = 0;
memAccess->count++;
switch (in->operation) {
case OPERATION_READ:
out->ready = 1;
out->reg = in->reg;
out->val = memAccess->mem[in->address];
break;
case OPERATION_WRITE:
memAccess->mem[in->address] = in->value;
break;
case OPERATION_NONE:
out->ready = 1;
out->reg = in->reg;
out->val = in->value;
break;
}
}