Blame view

main.c 667 Bytes
Imanol-Mikel Barba Sabariego authored
1
#include <stdio.h>
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);
}
Imanol-Mikel Barba Sabariego authored
15
16
17

int main(int argc, char** argv)
{
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();
Imanol-Mikel Barba Sabariego authored
31
32
    return 0;
}