-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypedefine.cpp
More file actions
97 lines (96 loc) · 1.99 KB
/
Typedefine.cpp
File metadata and controls
97 lines (96 loc) · 1.99 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
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
#include "Typedefine.h"
#include<string>
#include<cctype>
#include<stdio.h>
#include<iostream>
#include<cstdlib>
typefun findmode(std::string instruction,std::string &MOD,std::string &MOV,std::string &D)
{
typefun ret_val;
type t1,t2;
if(instruction[0]!='M'|| instruction[1]!='O' || instruction[2]!='V')
{
printf("Error Invalid Input\nExiting!!");
exit(27);
}
else
{
std::string T1,T2;
std::string::iterator i;
i=instruction.begin();
i=i+4;
while(*i!=',')
{
T1.push_back(*i);
i++;
}
i++;
while(i!=instruction.end())
{
T2.push_back(*i);
i++;
}
t1=findtype(T1);
t2=findtype(T2);
}
if(t1==REGISTER && t2== REGISTER)
{
ret_val= REGISTER_REGISTER;
MOD="11";
MOV="100010";
D="1";
}
else if(t1==REGISTER && t2==ADDRESS)
{
ret_val=REGISTER_ADDRESS;
MOD="00";
MOV="100010";
D="1";
}
else if(t1==ADDRESS && t2==REGISTER)
{
ret_val=ADDRESS_REGISTER;
MOD="00";
MOV="100010";
D="0";
}
else
{
ret_val=REGISTER_IMMEDIATE;
MOD="00";
MOV="1011";
D="WRRR";//Signifies Change in Code
}
return ret_val;
}
type findtype(std::string parameter)
{
type ret_val;
std::string::iterator i;
i=parameter.begin();
if(*i=='[')
{
ret_val=ADDRESS;
}
else if(parameter.length()>2 && *parameter.end()=='H')
{
ret_val=IMMEDIATE;
}
else if(*parameter.end()=='H'&& parameter.compare(0,2,"AH")!=0 && parameter.compare(0,2,"CH")!=0
&& parameter.compare(0,2,"DH")!=0 && parameter.compare(0,2,"BH")!=0)
{
ret_val=IMMEDIATE;
}
else
{
if(isdigit(*parameter.begin()))
{
ret_val=IMMEDIATE;
}
else
{
ret_val=REGISTER;
}
}
return ret_val;
}