-
Notifications
You must be signed in to change notification settings - Fork 0
/
um.c
42 lines (34 loc) · 975 Bytes
/
um.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
/*
* um.c
*
* This is the main file for the um homework.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "IO.h"
#include "Memory.h"
#include "Actions.h"
int main(int argc, char **argv) {
if(argc != 2) {
fprintf(stderr, "Usage: ./um [filename]\n");
} else {
UArray_T segmentZero = setInstructions(argv[1]);
Memory_T currMemory = Memory_new(segmentZero);
uint32_t counter = 0;
uint32_t currentWord = 0;
uint32_t *registers = malloc(8*(sizeof(uint32_t)));
for(int i = 0; i < 8; i++) {
registers[i] = 0;
}
while((int)counter < UArray_length(Seq_get(currMemory->memory, 0)) ) {
currentWord = *(uint32_t*)UArray_at(Seq_get(currMemory->memory, 0),
counter);
doCommand(currentWord, currMemory, ®isters, &counter);
}
free(registers);
Memory_free(currMemory);
}
return 0;
}