-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDavid.cs
More file actions
60 lines (55 loc) · 1.37 KB
/
David.cs
File metadata and controls
60 lines (55 loc) · 1.37 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
// Exit Instruction
public class Exit : IInstruction {
private readonly int _exitCode;
public Exit(int exitCode = 0) {
_exitCode = exitCode & 0x00FF_FFFF;
}
public int Encode() {
return (0b0000 << 24) | _exitCode;
}
}
// Swap Instruction
public class Swap : IInstruction {
private readonly int _from;
private readonly int _to;
public Swap(int from = 4, int to = 0) {
_from = from / 4;
_to = to / 4;
}
public int Encode() {
int fromEncoded = (_from & 0x0FFF) << 12;
int toEncoded = (_to & 0x0FFF);
return (0b0001 << 24) | fromEncoded | toEncoded;
}
}
// NOP Instruction
public class NOP : IInstruction {
public int Encode() {
return (0b0010 << 24);
}
}
// Input Instruction
public class Input : IInstruction {
public int Encode() {
return (0b0100 << 24);
}
}
// String Input Instruction
public class Stinput : IInstruction {
private readonly int _unsignedChars;
public Stinput(int unsignedChars) {
if (unsignedChars < 0 || unsignedChars > 0x00FF_FFFF) {
unsignedChars = 0x00FF_FFFF;
}
_unsignedChars = unsignedChars;
}
public int Encode() {
return (0b0101 << 24) | _unsignedChars;
}
}
// Dump Instruction
public class Dump : IInstruction {
public int Encode() {
return (0b1110 << 28);
}
}