-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet_Type.cpp
More file actions
executable file
·68 lines (61 loc) · 1.06 KB
/
Get_Type.cpp
File metadata and controls
executable file
·68 lines (61 loc) · 1.06 KB
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
/**********************************************
int Get_Type()
功能:根据指令决定机器码的类型;
参数值为指令的内容;
返回值为整数,表示不同的格式:
1:R-type;
2:I-type1;
3:I-type2;
4:J-type;
-1:错误,在指令集中未找到该条指令。
**********************************************/
/*---------------------------------------------
have been tested!
-----------------------------------------------*/
#include<string>
#include<iostream>
#include"ir.h"
using namespace std;
int Get_Type(string ins)
{
int i;
string::iterator it;
for (it = ins.begin(); it != ins.end();)
{
if (*it == ' ')
{
ins.erase(it);
}
else
++it;
}
for (i = 0; i < IR_QUANTITY; i++)
if (ins == ir_set[i]) break;
if (i == IR_QUANTITY)
return -1; /*错误码*/
switch (i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
return 0;
case 5:
case 6:
case 7:
return 1;
case 8:
case 9:
case 10:
case 11:
case 12:
return 2;
case 13:
case 14:
return 3;
case 15:
return 4;
}
return 0;
}