-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRamInstructions.cs
136 lines (103 loc) · 3.72 KB
/
RamInstructions.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BasicCompiuter
{
class RamInstructions : RegistersClass
{
//private static DataGridView my_ram;
public const string AND_code = "0";
public const string AND_code_I = "8";
public const string ADD_code = "1";
public const string ADD_code_I = "9";
public const string LDA_code = "2";
public const string LDA_code_I = "A";
public const string STA_code = "3";
public const string STA_code_I = "B";
public const string BUN_code = "4";
public const string BUN_code_I = "C";
public const string BSA_code = "5";
public const string BSA_code_I = "D";
public const string ISZ_code = "6";
public const string ISZ_code_I = "E";
public static ushort AND(ushort reg_value, DataGridView my_ram )// input = AR , RAM
{
//DataGridViewRow selected_row = my_ram.Rows[address_reg];
//REG_DR = Convert.ToUInt16(selected_row.Cells["Hex"].Value.ToString(), 16);
REG_DR = reg_value;
REG_SC = 0;
REG_AC = (ushort) (REG_AC & REG_DR);
return REG_AC;
}
public static ushort ADD(ushort reg_value, DataGridView my_ram)
{
//how can I control signed numbers ?
//DataGridViewRow selected_row = my_ram.Rows[address_reg];
//REG_DR = Convert.ToUInt16(selected_row.Cells["Hex"].Value.ToString(), 16);
REG_DR = reg_value;
REG_SC = 0;
int temp;
if (REG_DR + REG_AC > 65535)
{
REG_E = 1;
temp = REG_AC + REG_DR - 65536;
}
else
{
REG_E = 0;
temp = REG_AC + REG_DR;
}
REG_AC = (ushort)temp;
return REG_AC;
}
public static ushort LDA(ushort reg_value, DataGridView my_ram)
{
//DataGridViewRow selected_row = my_ram.Rows[address_reg];
//REG_DR = Convert.ToUInt16(selected_row.Cells["Hex"].Value.ToString(), 16);
REG_DR = reg_value;
REG_SC = 0;
REG_AC = REG_DR;
//Console.WriteLine("REG AC = " + REG_AC);
//Console.WriteLine("REG AR = " + address_reg);
//Console.WriteLine(selected_row.Cells["Hex"].Value.ToString());
return REG_AC;
}
public static ushort STA(ushort address_reg, DataGridView my_ram)
{
my_ram.Rows[address_reg].Cells["Hex"].Value = Convert.ToString(REG_AC, 16);
REG_SC = 0;
return REG_AC;
}
public static ushort BUN(ushort address_reg, DataGridView my_ram)
{
REG_SC = 0;
REG_AR = address_reg;
REG_PC = address_reg;
return REG_PC;
}
public static ushort BSA(ushort address_reg, DataGridView my_ram)
{
my_ram.Rows[address_reg].Cells["Hex"].Value = Convert.ToString(REG_PC, 16);
//REG_AR = 1;
REG_PC = REG_AR;
REG_PC++;
REG_SC = 0;
return REG_PC;
}
public static ushort ISZ(ushort reg_variable, DataGridView my_ram)
{
//DataGridViewRow selected_row = my_ram.Rows[reg_varia];
//REG_DR = Convert.ToUInt16(selected_row.Cells["Hex"].Value.ToString(), 16);
REG_DR = reg_variable;
if (reg_variable == 0)
{
REG_PC += 1;
}
REG_SC = 0;
return REG_PC;
}
}
}