MIXAL
memory.h
Go to the documentation of this file.
1 #ifndef INCLUDE_MEMORY_H_
2 #define INCLUDE_MEMORY_H_
3 
4 #include <cstdint>
5 #include <string>
6 
12 namespace mixal {
13 
14 class Instructions;
15 
16 extern uint16_t CHAR_CODES[];
17 const int32_t CHAR_CODES_NUM = 56;
25 struct ComputerWord {
26  bool negative;
27  uint8_t byte1;
28  uint8_t byte2;
29  uint8_t byte3;
30  uint8_t byte4;
31  uint8_t byte5;
32 
34  ComputerWord();
39  explicit ComputerWord(int32_t value);
44  explicit ComputerWord(const std::string& chars);
46  ComputerWord(bool _negative, uint8_t _byte1, uint8_t _byte2, uint8_t _byte3, uint8_t _byte4, uint8_t _byte5);
51  ComputerWord(char sign, uint8_t _byte1, uint8_t _byte2, uint8_t _byte3, uint8_t _byte4, uint8_t _byte5);
56  ComputerWord(bool _negative, uint16_t bytes12, uint8_t _byte3, uint8_t _byte4, uint8_t _byte5);
63  ComputerWord(char sign, uint16_t bytes12, uint8_t _byte3, uint8_t _byte4, uint8_t _byte5);
64 
66  void reset();
67 
72  bool operator==(const ComputerWord& word) const;
76  friend std::ostream& operator<<(std::ostream& out, const ComputerWord& word);
80  std::string getBytesString() const;
81 
86  uint8_t operator[](int index) const;
91  uint8_t& operator[](int index);
94  uint16_t bytes2(int index1, int index2) const;
99  uint16_t bytes12() const;
104  uint16_t bytes23() const;
109  uint16_t bytes34() const;
114  uint16_t bytes45() const;
119  int32_t value() const;
120 
128  int16_t addressValue() const;
134  inline uint16_t address() const { return bytes12(); }
140  inline uint8_t index() const { return byte3; }
147  inline uint8_t field() const { return byte4; }
153  inline uint8_t operation() const { return byte5; }
154 
156  void setAddress(int16_t address);
158  void setAddress(bool negative, uint16_t address);
160  inline void setIndex(uint8_t index) { byte3 = index; }
162  inline void setField(uint8_t field) { byte4 = field; }
164  inline void setOperation(uint8_t operation) { byte5 = operation; }
165 
172  uint8_t getAt(int32_t index) const { return (*this)[index]; }
174  std::string getCharacters() const;
185  void set(int32_t value);
197  void set(const std::string& chars);
205  void set(int index, uint8_t val);
207  void set(bool negative, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5);
212  void set(char sign, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5);
219  void set(bool negative, uint16_t bytes12, uint8_t byte3, uint8_t byte4, uint8_t byte5);
228  void set(char sign, uint16_t bytes12, uint8_t byte3, uint8_t byte4, uint8_t byte5);
229 };
230 
231 }; // namespace mixal
232 
233 
234 #endif // INCLUDE_MEMORY_H_
mixal::ComputerWord::address
uint16_t address() const
Definition: memory.h:134
mixal::CHAR_CODES_NUM
const int32_t CHAR_CODES_NUM
Definition: memory.h:17
mixal::ComputerWord::bytes23
uint16_t bytes23() const
Definition: memory.cpp:120
mixal::ComputerWord::setField
void setField(uint8_t field)
Definition: memory.h:162
mixal::ComputerWord::bytes45
uint16_t bytes45() const
Definition: memory.cpp:128
mixal::ComputerWord
Definition: memory.h:25
mixal::ComputerWord::operator<<
friend std::ostream & operator<<(std::ostream &out, const ComputerWord &word)
Definition: memory.cpp:24
mixal::ComputerWord::bytes12
uint16_t bytes12() const
Definition: memory.cpp:116
mixal::ComputerWord::getBytesString
std::string getBytesString() const
Definition: memory.cpp:71
mixal::ComputerWord::field
uint8_t field() const
Definition: memory.h:147
mixal::ComputerWord::setIndex
void setIndex(uint8_t index)
Definition: memory.h:160
mixal::ComputerWord::bytes34
uint16_t bytes34() const
Definition: memory.cpp:124
mixal::ComputerWord::reset
void reset()
Definition: memory.cpp:66
mixal::ComputerWord::index
uint8_t index() const
Definition: memory.h:140
mixal::ComputerWord::getAt
uint8_t getAt(int32_t index) const
Definition: memory.h:172
mixal::ComputerWord::operator[]
uint8_t operator[](int index) const
Definition: memory.cpp:84
mixal::ComputerWord::setAddress
void setAddress(int16_t address)
Definition: memory.cpp:149
mixal::ComputerWord::addressValue
int16_t addressValue() const
Definition: memory.cpp:141
mixal::ComputerWord::value
int32_t value() const
Definition: memory.cpp:132
mixal::ComputerWord::set
void set(int32_t value)
Definition: memory.cpp:178
mixal::CHAR_CODES
uint16_t CHAR_CODES[]
Definition: memory.cpp:9
mixal::ComputerWord::getCharacters
std::string getCharacters() const
Definition: memory.cpp:165
mixal::ComputerWord::operator==
bool operator==(const ComputerWord &word) const
Definition: memory.cpp:18
mixal::ComputerWord::bytes2
uint16_t bytes2(int index1, int index2) const
Definition: memory.cpp:110
mixal::ComputerWord::operation
uint8_t operation() const
Definition: memory.h:153
mixal::ComputerWord::ComputerWord
ComputerWord()
Definition: memory.cpp:32
mixal::ComputerWord::setOperation
void setOperation(uint8_t operation)
Definition: memory.h:164