https://github.com/akkartik/mu/blob/main/010vm.cc
1
2
3
4
5
6
7
8 :(before "End Types")
9 enum {
10 EAX,
11 ECX,
12 EDX,
13 EBX,
14 ESP,
15 EBP,
16 ESI,
17 EDI,
18 NUM_INT_REGISTERS,
19 };
20 union reg {
21 int32_t i;
22 uint32_t u;
23 };
24 :(before "End Globals")
25 reg Reg[NUM_INT_REGISTERS] = { {0} };
26 uint32_t EIP = 1;
27 :(before "End Reset")
28 bzero(Reg, sizeof(Reg));
29 EIP = 1;
30
31 :(before "End Types")
32 const int NUM_XMM_REGISTERS = 8;
33 float Xmm[NUM_XMM_REGISTERS] = { 0.0 };
34 const string Xname[NUM_XMM_REGISTERS] = { "XMM0", "XMM1", "XMM2", "XMM3", "XMM4", "XMM5", "XMM6", "XMM7" };
35 :(before "End Reset")
36 bzero(Xmm, sizeof(Xmm));
37
38 :(before "End Help Contents")
39 cerr << " registers\n";
40 :(before "End Help Texts")
41 put_new(Help, "registers",
42 "SubX supports 16 registers: eight 32-bit integer registers and eight single-precision\n"
43 "floating-point registers. From 0 to 7, they are:\n"
44 " integer: EAX ECX EDX EBX ESP EBP ESI EDI\n"
45 " floating point: XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7\n"
46 "ESP contains the top of the stack.\n"
47 "\n"
48 "-- 8-bit registers\n"
49 "Some instructions operate on eight *overlapping* 8-bit registers.\n"
50 "From 0 to 7, they are:\n"
51 " AL CL DL BL AH CH DH BH\n"
52 "The 8-bit registers overlap with the 32-bit ones. AL is the lowest signicant byte\n"
53 "of EAX, AH is the second lowest significant byte, and so on.\n"
54 "\n"
55 "For example, if EBX contains 0x11223344, then BL contains 0x44, and BH contains 0x33.\n"
56 "\n"
57 "There is no way to access bytes within ESP, EBP, ESI or EDI.\n"
58 "\n"
59 "For complete details consult the IA-32 software developer's manual, volume 2,\n"
60 "table 2-2, \"32-bit addressing forms with the ModR/M byte\".\n"
61 "It is included in this repository as 'modrm.pdf'.\n"
62 "The register encodings are described in the top row of the table, but you'll need\n"
63 "to spend some time with it.\n"
64 "\n"
65 "-- flag registers\n"
66 "Various instructions (particularly 'compare') modify one or more of four 1-bit\n"
67 "'flag' registers, as a side-effect:\n"
68 "- the sign flag (SF): usually set if an arithmetic result is negative, or\n"
69 " reset if not.\n"
70 "- the zero flag (ZF): usually set if a result is zero, or reset if not.\n"
71 "- the carry flag (CF): usually set if an arithmetic result overflows by just one bit.\n"
72 " Useful for operating on unsigned numbers.\n"
73 "- the overflow flag (OF): usually set if an arithmetic result overflows by more\n"
74 " than one bit. Useful for operating on signed numbers.\n"
75 "The flag bits are read by conditional jumps.\n"
76 "\n"
77 "For complete details on how different instructions update the flags, consult the IA-32\n"
78 "manual (volume 2). There's various versions of it online, such as https://c9x.me/x86,\n"
79 "though of course you'll need to be careful to ignore instructions and flag registers\n"
80 "that SubX doesn't support.\n"
81 "\n"
82 "It isn't simple, but if this is the processor you have running on your computer.\n"
83 "Might as well get good at it.\n"
84 );
85
86 :(before "End Globals")
87
88 bool SF = false;
89 bool ZF = false;
90 bool CF = false;
91 bool OF = false;
92 :(before "End Reset")