-
Notifications
You must be signed in to change notification settings - Fork 0
/
prntFunctions.c
87 lines (84 loc) · 3.12 KB
/
prntFunctions.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include "CVM.h"
/*
* This function reads every number in the array by incrementing an index called 'i', and doing so until
* i reaches the end of the array. For every position it prints the index in the array where the instruction is found,
* the associated instruction (the associations between numbers and instructions are defined in the header file) and
* the relative parameters, if present. Then the index is incremented by adding to it the number of parameters expected
* by the instruction it just read plus one (the array cell of the instruction itself).
*/
void prntFunction(int instruction_array[], int length){
int i = 0;
while(i < length){
switch(instruction_array[i]){
case HALT:
printf("[%3d] HALT\n", i);
i += 1;
break;
case DISPLAY:
printf("[%3d] DISPLAY R%d\n", i, instruction_array[i+1]);
i += 2;
break;
case PRINT_STACK:
printf("[%3d] PRINT_STACK %d\n", i, instruction_array[i+1]);
i += 2;
break;
case PUSH:
printf("[%3d] PUSH R%d\n", i, instruction_array[i+1]);
i += 2;
break;
case POP:
printf("[%3d] POP R%d\n", i, instruction_array[i+1]);
i += 2;
break;
case MOV:
printf("[%3d] MOV R%d %d\n", i, instruction_array[i+1], instruction_array[i+2]);
i += 3;
break;
case CALL:
printf("[%3d] CALL %d\n", i, instruction_array[i+1]);
i += 2;
break;
case RET:
printf("[%3d] RET\n", i);
i += 1;
break;
case JMP:
printf("[%3d] JMP %d\n", i, instruction_array[i+1]);
i += 2;
break;
case JZ:
printf("[%3d] JZ %d\n", i, instruction_array[i+1]);
i += 2;
break;
case JPOS:
printf("[%3d] JPOS %d\n", i, instruction_array[i+1]);
i += 2;
break;
case JNEG:
printf("[%3d] JNEG %d\n", i, instruction_array[i+1]);
i += 2;
break;
case ADD:
printf("[%3d] ADD R%d R%d\n", i, instruction_array[i+1], instruction_array[i+2]);
i += 3;
break;
case SUB:
printf("[%3d] SUB R%d R%d\n", i, instruction_array[i+1], instruction_array[i+2]);
i += 3;
break;
case MUL:
printf("[%3d] MUL R%d R%d\n", i, instruction_array[i+1], instruction_array[i+2]);
i += 3;
break;
case DIV:
printf("[%3d] DIV R%d R%d\n", i, instruction_array[i+1], instruction_array[i+2]);
i += 3;
break;
default:
printf("Command not found.\n");
exit(1);
}
}
}