-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.h
127 lines (93 loc) · 2.25 KB
/
decoder.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#ifndef DECODER_H
#define DECODER_H
#define INITIAL_ADDRESS 0x400000
enum funct_opcodes {
FUNCT_SUB = 0x22,
FUNCT_OR = 0x25,
FUNCT_AND = 0x24,
};
enum opcodes {
OPCODE_R_TYPE = 0x0,
OPCODE_SW = 0x2B,
OPCODE_LW = 0x23,
OPCODE_BEQ = 0x4,
OPCODE_SLTIU = 0xB,
OPCODE_J = 0x2,
OPCODE_JAL = 0x3,
OPCODE_ADDI = 0x8,
OPCODE_ORI = 0xD,
OPCODE_ANDI = 0xC,
OPCODE_SLTI = 0xA,
OPCOE_XORI = 0xE,
OPCODE_BGEZ = 0x1,
OPCODE_BGTZ = 0x7,
OPCODE_BLEZ = 0x6,
OPCODE_BNE = 0x5,
};
enum registers {
ZERO = 0,
AT = 1,
V0 = 2,
V1 = 3,
A0 = 4,
A1 = 5,
A2 = 6,
A3 = 7,
T0 = 8,
T1 = 9,
T2 = 10,
T3 = 11,
T4 = 12,
T5 = 13,
T6 = 14,
T7 = 15,
S0 = 16,
S1 = 17,
S2 = 18,
S3 = 19,
S4 = 20,
S5 = 21,
S6 = 22,
S7 = 23,
T8 = 24,
T9 = 25,
K0 = 26,
K1 = 27,
GP = 28,
SP = 29,
FP = 30,
RA = 31,
};
bool isLabel(char *string);
int getLabelAddress(int labelInstructionCount);
char *getRegisterString(int register);
char *getOperationWithFunctString(int funct);
char *getOperationString(int opcode);
char *mountTypeJInstructionString(char **splittedInstruction);
char *mountTypeRInstructionString(char **splittedInstruction);
char *mountTypeIInstructionString(char **splittedInstruction);
int getAddressFromJInstruction(char *instruction);
char *shortJumpAddress(char *jump);
char *fixJumpAddress(char *jump);
int binaryStringToInt(char *binaryStr);
char *hexToBinary(const char *hexValue);
int hexStringToInt(char *hexString);
char **splitITypeInstruction(char *binaryInstruction);
char **splitRTypeInstruction(char *binaryInstruction);
char **splitJTypeInstruction(char *binaryInstruction);
int getOpcode(char *binaryString);
char *createLabel();
char *getLabel(int i);
bool isBeqInstruction(char *instruction);
int getBeqInstructionDesloc(char *instruction);
char *getLabelFromInstruction(char *instruction);
int calculateAddress(int currentAddress, int desloc);
char *removeBeqPrefix(char *instruction);
int calculateIndexFromAddress(int address);
int binaryStringToIntWithNegatives(char *binaryStr);
#endif