-
Notifications
You must be signed in to change notification settings - Fork 0
/
Register01.cpp
103 lines (96 loc) · 2.2 KB
/
Register01.cpp
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
/*----------------------------------------------------------*/
//Author: Steven Chambers
//Student ID: *20342421
//E-mail: [email protected]
//Course: CMSC 3833 - Computer Organization II
//CRN: 11404, Autumn 2014
//Project: p01
//Due: November 10, 2014
//Account: tt002
/*---------------------------------------------------------*/
#include "Register01.h"
Register::Register(int numFlipFlops)
{
this->numFlipFlops = numFlipFlops;
for(int i = 0; i < numFlipFlops;i++)
{
flipflops.push_back(Flipflop());
}
}
string Register::regOr(Register& compare)
{
string output = string(numFlipFlops, '0');
for(int i = 0; i < numFlipFlops; i++)
{
if(!(this->flipflops.at(i).getState()== '0' && compare.flipflops.at(i).getState()== '0'))
output[i] = '1';
}
return output;
}
string Register::regAnd(Register& compare)
{
string output = string(numFlipFlops, '0');
for(int i = 0; i < numFlipFlops; i++)
{
if(this->flipflops.at(i).getState()== '1' && compare.flipflops.at(i).getState()== '1')
output[i] = '1';
}
return output;
}
string Register::regNot()
{
string output = string(numFlipFlops, '0');
for(int i = 0; i < numFlipFlops; i++)
{
output[i] = this->flipflops.at(i).compState();
}
return output;
}
string Register::regXOR(Register& compare)
{
string tmp = this->regXNOR(compare);
for(int i = 0; i < numFlipFlops; i++)
{
if(tmp[i] == '1')
tmp[i] = '0';
else
tmp[i] = '1';
}
return tmp;
}
string Register::regXNOR(Register& compare)
{
string R0not = this->regNot();
string R1not = compare.regNot();
string tmp= string(numFlipFlops, '0');
for(int i = 0;i < numFlipFlops; i++)
{
if(R0not[i] == '1'&& R1not[i] =='1')
tmp[i] = '1';
}
string R0andR1 = this->regAnd(compare);
string output= string(numFlipFlops,'0');
for(int i = 0; i < numFlipFlops; i++)
{
if(!(tmp[i] == '0' && R0andR1[i] == '0'))
output[i] = '1';
}
return output;
}
void Register::regLoad(string toLoad)
{
for(int i = 0; i < numFlipFlops; i++)
{
this->flipflops.at(i).setState(toLoad[i]);
}
}
string Register::printReg()
{
string output = string(numFlipFlops, '0');
for(int i = 0; i < numFlipFlops;i++)
{
if(this->flipflops.at(i).getState() == '1')
output[i] = '1';
}
return output;
}