-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMano.cpp
More file actions
177 lines (162 loc) · 2.49 KB
/
Mano.cpp
File metadata and controls
177 lines (162 loc) · 2.49 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
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
175
176
177
#include<iostream>
using namespace std;
static bool acm[8];
static bool c_flag;
// Instructions
void display_acm ();
void and_acm (bool[]);
void add_bin (bool[]);
// void load_acm (bool[]);
// void store_acm (bool[]);
// void bun (bool[]);
// void bsa (bool[]);
// void isz (bool[]);
void clear_acm ();
void clear_e ();
void cmp_acm ();
void cmp_e ();
void cycle_right ();
void cycle_left ();
// void inc_acm ();
// void spa ();
// void sna ();
// void sza ();
// void sze ();
// void hlt ();
// void inp ();
// void out ();
// void ski ();
// void sko ();
// void ion ();
// void iof ();
// Functions
void display_acm ()
{
static int i;
cout << "Instruction " << i << endl;
cout << " AC " << endl;
for (int k = 0; k < 8; k++)
{
cout << acm[k];
}
cout << endl;
cout << endl << "E [" << c_flag << "]" << endl;
cout << endl;
i++;
}
void add_bin (bool b[])
{
int c = 0, s;
for (int k = 7; k >= 0; k--)
{
s = (acm[k] ^ b[k]) ^ c;
c = (acm[k] & b[k]) || (acm[k] & c) || (b[k] & c);
acm[k] = s;
}
c_flag = c;
}
void cmp_acm ()
{
for (int k = 0; k < 8; k++)
{
acm[k] = acm[k] ^ 1;
}
}
void and_acm (bool n[])
{
for (int k = 0; k < 8; k++)
{
acm[k] = acm[k] & n[k];
}
}
void cmp_e ()
{
c_flag = c_flag ^ 1;
}
void cycle_left ()
{
bool t = c_flag;
c_flag = acm[0];
for (int k = 0; k < 7; k++)
{
acm[k] = acm[k+1];
}
acm[7] = t;
}
void cycle_right ()
{
bool t = c_flag;
c_flag = acm[7];
for (int k = 7; k > 0; k--)
{
acm[k] = acm[k-1];
}
acm[0] = t;
}
void clear_acm ()
{
for (int k = 0; k < 8; k++)
{
acm[k] = 0;
}
}
void clear_e ()
{
c_flag = 0;
}
int main()
{
bool p[] = {0,1,0,1,1,1,0,0};
bool q[] = {1,1,1,0,0,1,0,0};
// 0
display_acm();
// 1
add_bin(p);
display_acm();
// 2
add_bin(p);
display_acm();
// 3
add_bin(p);
display_acm();
// 4
add_bin(p);
display_acm();
// 5
cycle_left();
display_acm();
// 6
cycle_left();
display_acm();
// 7
cycle_left();
display_acm();
// 8
cycle_right();
display_acm();
// 9
cmp_e();
display_acm();
// 10
and_acm(p);
display_acm();
// 11
cycle_right();
display_acm();
// 12
cmp_acm();
display_acm();
// 13
cmp_acm();
display_acm();
// 14
add_bin(q);
display_acm();
// 15
clear_acm();
display_acm();
// 16
clear_e();
display_acm();
return 0;
}