-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (63 loc) · 1.8 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "cpu.h"
#include "generator.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(int argc, char **argv)
{
srand(time(NULL)); // Inicializacao da semente para os numeros aleatorios.
if (argc != 3)
{
printf("Numero de argumentos invalidos! Sao 3.\n");
printf("Linha de execucao: ./exe TIPO_INSTRUCAO [TAMANHO_RAM|ARQUIVO_DE_INSTRUCOES]\n");
printf("\tExemplo 1 de execucao: ./exe random 10\n");
printf("\tExemplo 3 de execucao: ./exe file arquivo_de_instrucoes.txt\n");
return 0;
}
int ramSize;
Machine machine;
Instruction *instructions;
if (strcmp(argv[1], "random") == 0)
{
ramSize = atoi(argv[2]);
instructions = generateRandomInstructions(ramSize);
}
else if (strcmp(argv[1], "file") == 0)
{
instructions = readInstructions(argv[2], &ramSize);
}
else if (strcmp(argv[1], "division") == 0)
{
ramSize = atoi(argv[2]);
instructions = generateDivisionInstructions(88, 7);
}
else if (strcmp(argv[1], "multiply") == 0)
{
ramSize = atoi(argv[2]);
instructions = generateMultiplicationInstructions(9, 9, 0);
}
else if (strcmp(argv[1], "exponentiation") == 0)
{
ramSize = atoi(argv[2]);
instructions = generateExponentiationInstructions(5, 4);
}
else if (strcmp(argv[1], "fibonacci") == 0)
{
ramSize = atoi(argv[2]);
instructions = generateFibonacciInstructions(14);
}
else
{
printf("Opcao invalida.\n");
return 0;
}
printf("Iniciando a maquina...\n");
start(&machine, instructions, ramSize);
printRAM(&machine);
run(&machine);
printRAM(&machine);
stop(&machine);
printf("Finalizando a maquina...\n");
return 0;
}