-
Notifications
You must be signed in to change notification settings - Fork 0
/
onememoryword.cc
110 lines (95 loc) · 3.22 KB
/
onememoryword.cc
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
#include "onememoryword.h"
/***************************************************************************
*3456789 123456789 123456789 123456789 123456789 123456789 123456789 123456
* Class 'OneMemoryWord' as a container for one word of memory.
*
* Author/copyright: Duncan A. Buell. All rights reserved.
* Used with permission and modified by: Austin Staton
* Date: 21 October 2018
*
* This exists almost entirely to allow the text of a function to indicate
* what one is extracting from the 16 bit pattern that is a memory word,
* and to format the bits for printing as 3 + 1 + 12 for opcode, indirect,
* and address.
**/
/***************************************************************************
* Constructor
**/
OneMemoryWord::OneMemoryWord() {
}
/***************************************************************************
* Constructor
**/
OneMemoryWord::OneMemoryWord(string thestring) {
Initialize(thestring);
}
/***************************************************************************
* Destructor
**/
OneMemoryWord::~OneMemoryWord() {
}
/***************************************************************************
* Accessors and Mutators
**/
/***************************************************************************
* Accessor for the 'address_bits_'.
**/
string OneMemoryWord::GetAddressBits() const {
return bit_pattern_.substr(4);
}
/***************************************************************************
* Accessor for the 'bit_pattern_'.
**/
string OneMemoryWord::GetBitPattern() const {
return bit_pattern_;
}
/***************************************************************************
* Accessor for the 'indirect_flag_'.
**/
string OneMemoryWord::GetIndirectFlag() const {
return bit_pattern_.substr(3, 1);
}
/***************************************************************************
* Accessor for the 'mnemonic_bits_'.
**/
string OneMemoryWord::GetMnemonicBits() const {
return bit_pattern_.substr(0, 3);
}
/***************************************************************************
* Mutator for the 'bit_pattern_'.
**/
void OneMemoryWord::SetBitPattern(string what) {
bit_pattern_ = what;
}
/***************************************************************************
* General functions.
**/
/***************************************************************************
* Function 'Initialize'.
**/
void OneMemoryWord::Initialize(string bit_pattern) {
bit_pattern_ = bit_pattern;
}
/***************************************************************************
* Function 'ToString'.
* This function formats a 'OneMemoryWord' for prettyprinting.
* This makes sense if the word is an instruction. If it's just a number or a
* bit pattern, then the prettyprinting makes less sense. But we do the
* prettyprinting because taking out spaces in reading a line is easier than
* adding in spaces that would separate mnemonic, etc.
*
* Returns:
* the prettyprint string for printing
**/
string OneMemoryWord::ToString() const {
#ifdef EBUG
Utils::log_stream << "enter ToString" << endl;
#endif
string sss = "";
sss += this->GetMnemonicBits() + " " + this->GetIndirectFlag() + " " +
this->GetAddressBits();
#ifdef EBUG
Utils::log_stream << "leave ToString" << endl;
#endif
return sss;
}