|
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include <string.h>
#include "mem.h"
#include "stack.h"
void load_program(const char* path)
{
FILE *fp = fopen(path,"r");
fseek(fp, 0L, SEEK_END);
long file_size = ftell(fp);
rewind(fp);
fread(mem,1,(size_t)file_size,fp);
fclose(fp);
}
|
|
18
19
20
21
22
23
24
25
26
27
28
29
30
|
if(argc != 2)
{
printf("Invalid argument\n\n");
printf(argv[0]);
printf(" path_to_binary\n");
return 1;
}
initialize_stack();
memset(regs,0x00,sizeof(short)*NUM_REGISTERS);
memset(mem,0x00,sizeof(short)*MEMSIZE);
load_program(argv[1]);
start_execution();
free_stack();
|