-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvi.cpp
More file actions
125 lines (107 loc) · 2.17 KB
/
mvi.cpp
File metadata and controls
125 lines (107 loc) · 2.17 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
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
#include "headers.h"
#include <sstream>
#include "methods.h"
using namespace std;
//mov a,b
int mvi(elements *e)
{
string inst = e->memory[e->pc];
string a0,a1,a2;
stringstream ss(inst);
getline(ss,a0,' ');
getline(ss,a1,',');
getline(ss,a2);
//cout<<a0<<a1<<a2<<"**"<<endl;
if(a1.length()>1 || a2.length()>2 )return 0;
if(a2.length()==1)
a2="0"+a2;
switch(a2[0])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':break;
case 'a':a2[0]='A';break;
case 'b':a2[0]='B';break;
case 'c':a2[0]='C';break;
case 'd':a2[0]='D';break;
case 'e':a2[0]='E';break;
case 'f':a2[0]='F';break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':break;
default : return 0;
}
switch(a2[1])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':break;
case 'a':a2[1]='A';break;//a2[1]=(char)(a2[1]-32);break;
case 'b':a2[1]='B';break;//a2[1]=(char)(a2[1]-32);break;
case 'c':a2[1]='C';break;//a2[1]=(char)(a2[1]-32);break;
case 'd':a2[1]='D';break;//a2[1]=(char)(a2[1]-32);break;
case 'e':a2[1]='E';break;//a2[1]=(char)(a2[1]-32);break;
case 'f':a2[1]='F';break;//a2[1]=(char)(a2[1]-32);break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':break;
default : return 0;
}
//rdd=destination reg....
int rdd;
switch(a1[0])
{
case 'A':
case 'a':rdd=0;break;
case 'B':
case 'b':rdd=1;break;
case 'C':
case 'c':rdd=2;break;
case 'D':
case 'd':rdd=3;break;
case 'E':
case 'e':rdd=4;break;
case 'H':
case 'h':rdd=5;break;
case 'L':
case 'l':rdd=6;break;
case 'M':
case 'm':break;
default : return 0;
}
if(a1[0]=='m' ||a1[0]=='M')
{
string memo="";
memo.append(e->registers[5]);
memo.append(e->registers[6]);
e->memory[memo]=a2;
}
else
{
e->registers[rdd]=a2;
//cout<<e->registers[rdd]<<"***"<<endl;
}
//increment(e->pc);e->memory[pc]=inst;
//increment(e->pc);
return 1;
}