-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.hpp
More file actions
59 lines (56 loc) · 1.25 KB
/
Copy pathtype.hpp
File metadata and controls
59 lines (56 loc) · 1.25 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
//
// Created by yhy79 on 2020/7/6.
//
#ifndef RISC_V_TYPE_HPP
#define RISC_V_TYPE_HPP
class Byte { // type Byte
public:
unsigned char b;
Byte(unsigned char b) : b(b) {}
Byte() {b = 0;}
operator int() {
return int(b);
}
};
/*
* use union to deal with the space that may be both one int and four char
*/
union HalfWord { // type HalfWord
short num;
unsigned short u_num;
struct {
unsigned char b1, b2;
} b;
public:
HalfWord() {num = 0;}
HalfWord(short num) : num(num) {}
HalfWord(unsigned u_num) : u_num(u_num) {}
HalfWord(unsigned char b1, unsigned char b2) {
b.b1 = b1;
b.b2 = b2;
}
operator int() {
return int(num);
}
};
union Word { // type Word
int num;
unsigned int u_num;
struct {
unsigned char b4, b3, b2, b1;
} b;
public:
Word() {num = 0;}
Word(int num) : num(num) {}
Word(unsigned int u_num) : u_num(u_num) {}
Word(unsigned char b1, unsigned char b2, unsigned char b3, unsigned char b4) {
b.b1 = b1;
b.b2 = b2;
b.b3 = b3;
b.b4 = b4;
}
operator int() {
return num;
}
};
#endif //RISC_V_TYPE_HPP