-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegInstructions.cs
174 lines (136 loc) · 3.52 KB
/
RegInstructions.cs
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BasicCompiuter
{
class RegInstructions : RegistersClass
{
//hex
public const string CLA_code = "7800";
public const string CLE_code = "7400";
public const string CMA_code = "7200";
public const string CME_code = "7100";
public const string CIR_code = "7080";
public const string CIL_code = "7040";
public const string INC_code = "7020";
public const string SPA_code = "7010";
public const string SNA_code = "7008";
public const string SZE_code = "7002";
public const string SZA_code = "7004";
public const string HLT_code = "7001";
public static bool CLA_instruction()
{
REG_AC = 0;
return true;
}
public static bool CLE_instruction()
{
REG_E = 0;
return true;
}
public static bool CMA_instruction()
{
//Complement AC
REG_AC = (ushort) ~REG_AC;
return true;
}
public static bool CME_instruction()
{
switch(REG_E)
{
case 0:
REG_E = 1;
break;
case 1:
REG_E = 0;
break;
default:
return false;
}
return true;
}
public static bool CIR_instruction()
{
byte right_bit = 0;
ushort add_e = 0;
//is last bit 1 ?
if (REG_AC % 2 == 1)
{
right_bit = 1;
}
// is E 1 ?
if (REG_E >= 1)
{
add_e = 32768;
}
REG_AC = (ushort)(REG_AC >> 1);// shift right
REG_AC += add_e;
REG_E = right_bit; // fill E
return true;
}
public static bool CIL_instruction()
{
//string bitwise_str = Convert.ToString(REG_AC);
//ushort left_bit =(ushort) Convert.ToUInt16(bitwise_str, 2);
byte left_bit= 0;
if (REG_AC >= 32768)
{
left_bit = 1;
}
else
{
left_bit = 0;
}
REG_AC = (ushort)(REG_AC << 1);
REG_AC += REG_E;
REG_E = left_bit;
return true;
}
public static bool INC_instruction()
{
REG_AC += 1;
return true;
}
public static bool SPA_instruction()
{
// AC[15] == 0
if (REG_AC < 32768)
{
REG_PC += 1;
}
return true;
}
public static bool SNA_instruction()
{
if (REG_AC >= 32768)
{
REG_PC += 1;
}
return true;
}
public static bool SZA_instruction()
{
if (REG_AC == 0)
{
REG_PC += 1;
}
return true;
}
public static bool SZE_instruction()
{
if (REG_E == 0)
{
REG_PC += 1;
}
return true;
}
public static bool HLT_instruction()
{
REG_S = 0;
// and ??
return true;
}
}
}