main.c
667 Bytes
#include <stdio.h>
#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);
}
int main(int argc, char** argv)
{
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();
return 0;
}