-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConditionCodes.C
More file actions
83 lines (77 loc) · 2.52 KB
/
ConditionCodes.C
File metadata and controls
83 lines (77 loc) · 2.52 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
#include <iostream>
#include <iomanip>
#include "ConditionCodes.h"
#include "Tools.h"
//cc_instance will be initialized to reference the single
//instance of ConditionCodes
ConditionCodes * ConditionCodes::ccInstance = NULL;
/**
* ConditionCodes constructor
* initialize the codes field to 0
*/
ConditionCodes::ConditionCodes() {
codes = 0;
}
/**
* getInstance
* if ccInstance is NULL then getInstance creates the
* single ConditionCodes instance and sets ccInstance
* to that. Otherwise, it returns ccInstance
*
* @return ccInstance
*/
ConditionCodes * ConditionCodes::getInstance() {
if (ccInstance == NULL) ccInstance = new ConditionCodes();
return ccInstance;
}
/*
* getConditionCode
* accepts a condition code number (OF, SF, or ZF) and returns
* the value of the condition code
*
* @param ccNum equal to either OF, SF, or ZF
* @return the value of bit ccNum out of codes. if ccNum is
* out of range then returns false
* @return error is set to true if ccNum is out of range and
* false otherwise
*/
bool ConditionCodes::getConditionCode(int32_t ccNum, bool & error) {
if (ccNum == ZF || ccNum == OF || ccNum == SF) {
error = false;
return Tools::getBits(codes, ccNum, ccNum);
}
error = true;
return false;
}
/*
* setConditionCode
* accepts a condition code number (OF, SF, or ZF) and value
* (true or false) and sets the condition code bit to that
* value (1/true or 0/false). if the ccNum value is out of
* range then codes does not get modified.
*
* @param value to set the condition code bit to (true/1 or false/0)
* @param ccNum condition code number, either OF, SF, or ZF
* @return error is set to true if ccNum is out of range and
* false otherwise
*/
void ConditionCodes::setConditionCode(bool value, int32_t ccNum, bool & error) {
if (ccNum == ZF || ccNum == OF || ccNum == SF) {
error = false;
if (value) codes = Tools::setBits(codes, ccNum, ccNum);
else codes = Tools::clearBits(codes, ccNum, ccNum);
} else error = true;
}
/*
* dump
* outputs the values of the condition codes
*/
void ConditionCodes::dump() {
int32_t zf = Tools::getBits(codes, ZF, ZF);
int32_t sf = Tools::getBits(codes, SF, SF);
int32_t of = Tools::getBits(codes, OF, OF);
std::cout << std::endl;
std::cout << "ZF: " << std::hex << std::setw(1) << zf << " ";
std::cout << "SF: " << std::hex << std::setw(1) << sf << " ";
std::cout << "OF: " << std::hex << std::setw(1) << of << std::endl;
}