https://github.com/akkartik/mu/blob/master/017jump_disp8.cc
1
2
3
4
5 :(before "End Initialize Op Names")
6 put_new(Name, "eb", "jump disp8 bytes away (jmp)");
7
8 :(code)
9 void test_jump_disp8() {
10 run(
11 "== code 0x1\n"
12
13 " eb 05 \n"
14 " 05 00 00 00 01 \n"
15 " 05 00 00 00 02 \n"
16 );
17 CHECK_TRACE_CONTENTS(
18 "run: 0x00000001 opcode: eb\n"
19 "run: jump 5\n"
20 "run: 0x00000008 opcode: 05\n"
21 );
22 CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05");
23 }
24
25 :(before "End Single-Byte Opcodes")
26 case 0xeb: {
27 int8_t offset = static_cast<int>(next());
28 trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
29 EIP += offset;
30 break;
31 }
32
33
34
35 :(before "End Initialize Op Names")
36 put_new(Name, "74", "jump disp8 bytes away if equal, if ZF is set (jcc/jz/je)");
37
38 :(code)
39 void test_je_disp8_success() {
40 ZF = true;
41 run(
42 "== code 0x1\n"
43
44 " 74 05 \n"
45 " 05 00 00 00 01 \n"
46 " 05 00 00 00 02 \n"
47 );
48 CHECK_TRACE_CONTENTS(
49 "run: 0x00000001 opcode: 74\n"
50 "run: jump 5\n"
51 "run: 0x00000008 opcode: 05\n"
52 );
53 CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05");
54 }
55
56 :(before "End Single-Byte Opcodes")
57 case 0x74: {
58 const int8_t offset = static_cast<int>(next());
59 if (ZF) {
60 trace(Callstack_depth+1, "run") << "jump " << NUM(offset) << end();
61 EIP += offset;
62 }
63 break;
64 }
65
66 :(code)
67 void test_je_disp8_fail() {
68 ZF = false;
69 run(
70 "== code 0x1\n"
71
72 " 74 05 \n"
73 " 05 00 00 00 01 \n"
74 " 05 00 00 00 02 \n"
75 );
76 CHECK_TRACE_CONTENTS(
77 "run: 0x00000001 opcode: 74\n"
78 "run: 0x00000003 opcode: 05\n"
79 "run: 0x00000008 opcode: 05\n"
80 );
81 CHECK_TRACE_DOESNT_CONTAIN("run: jump 5");
82 }
83
84
85
86 :(before "End Initialize Op Names")
87 put_new(Name, "75", "jump disp8 bytes away if not equal, if ZF is not set (jcc/jnz/jne)");
88
89 :(code)
90 void test_jne_disp8_success() {
91 ZF = false;
92 run(
93 "== code 0x1\n"
94
95 " 75 05 \n"
96 " 05 00 00 00 01 \n"
97 " 05 00 00 00 02 \n"
98 );
99 CHECK_TRACE_CONTENTS(
100 "run: 0x00000001 opcode: 75\n"
101 "run: jump 5\n"
102 "run: 0x00000008 opcode: 05\n"
103 );
104 CHECK_TRACE_DOESNT_CONTAIN("run: 0x00000003 opcode: 05");
105 }
106
107 :(before "End Single-Byte Opcodes")
108 case 0x75: {
109 const int8_t offset = static_cast<int>(next());
110 if (!ZF) {
111 trace(Callstack_depth+1, "run") << "jump " << NUM